Skip to content

[OPT-39999] Mep-xlg-tags.json issues#5482

Open
AdobeLinhart wants to merge 7 commits intostagefrom
OPT-39999
Open

[OPT-39999] Mep-xlg-tags.json issues#5482
AdobeLinhart wants to merge 7 commits intostagefrom
OPT-39999

Conversation

@AdobeLinhart
Copy link
Contributor

@AdobeLinhart AdobeLinhart commented Mar 3, 2026

Adds a check to prevent getXLGListURL() from firing multiple times by utilizing promises. It should only perform the call once.

Behavior

  • Do not execute network call for mep-xlg-tags if signed out.
  • Execute a single network call for mep-xlg-tags if signed in.

Instructions

  • Open test URL
  • Open the network panel
  • Filter for mep-xlg-tags
  • Observe the amount of times called
  • Test both as a logged in and logged out user.

Before:
image

After:
image

Resolves: OPT-39999

Test URLs:

@AdobeLinhart AdobeLinhart requested a review from a team as a code owner March 3, 2026 00:56
@aem-code-sync
Copy link
Contributor

aem-code-sync bot commented Mar 3, 2026

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

Copy link
Contributor

@jpratt2 jpratt2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.
Verified: Only one call is seen in the network tab when logged in. (see attached) The content of the network call appears unharmed.

Image

Verified: there is no network call when logged out

@AdobeLinhart AdobeLinhart requested a review from a team March 6, 2026 22:35

config.mepXlgTagsURL = xlgUrl;
resolve(xlgUrl);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this locally and wanted to share a few things I noticed — mostly around how the caching and fetch flow interact. I think the intent makes sense, but a couple of edge cases seem to cause unexpected behavior:

  1. Undefined fetch case
    On the second call to getXLGListURL (from getEntitlementMap), the function returns undefined because config.mepXlgTagsURL is already truthy from the first call. That ends up calling fetchData(undefined), which results in a fetch("undefined") request (you can see it fail in the network/perf waterfall). So instead of skipping the duplicate download, we end up with an erroneous request, and the preloaded XLG data never actually gets consumed since getEntitlementMap never receives a valid URL.

  2. Cache getting reset
    After that second call, config.mepXlgTagsURL is set back to undefined, which means the “already fetched” guard wouldn’t hold if a third call were to happen.

  3. Promise wrapper
    isSignedInUser() looks to be synchronous, so wrapping it in new Promise(resolve => …) adds a microtask delay without really buying us anything.

One alternative that seems to avoid those issues is: kick off the fetch early and cache the Promise itself, so getEntitlementMap can reuse the same in‑flight/resolved response rather than re-deriving the URL each time:

export const getXLGListURL = (config) => {
  if (config.mepXlgTagsURL) return config.mepXlgTagsURL;
  if (!window.adobeIMS?.isSignedInUser()) return undefined;
  const sheet = config.env?.name === 'prod' ? 'prod' : 'stage';
  const rawUrl = `https://www.adobe.com/federal/assets/data/mep-xlg-tags.json?sheet=${sheet}`;
  config.mepXlgTagsURL = normalizePath(rawUrl);
  return config.mepXlgTagsURL;
};

export function prefetchXLGTags(config) {
  const url = getXLGListURL(config);
  if (!url) return;
  config.mepXlgTagsPromise = fetchData(url, DATA_TYPE.JSON);
}

Then in getEntitlementMap, reuse the cached promise:

const fetchedData = config.mepXlgTagsPromise  ? await config.mepXlgTagsPromise  : await fetchData(getXLGListURL(config), DATA_TYPE.JSON);

And in init, replace the loadLink preload with:

if (pzn || pznroc) prefetchXLGTags(config);

That should give us one fetch, no wasted preload, no undefined request, and the data actually gets consumed. And again — the isSignedInUser() guard to skip signed‑out users is great; I’d definitely keep that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I haven't really used promises since Angular. It was something Viv suggested. Updated to work as per your specifications.

@github-actions
Copy link
Contributor

This pull request is not passing all required checks. Please see this discussion for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR.

@github-actions
Copy link
Contributor

This PR has not been updated recently and will be closed in 7 days if no action is taken. Please ensure all checks are passing, https://github.com/orgs/adobecom/discussions/997 provides instructions. If the PR is ready to be merged, please mark it with the "Ready for Stage" label.

@github-actions github-actions bot added the Stale label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants