Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions unitylibs/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ export const [setLibs, getLibs] = (() => {
libs = (() => {
const { hostname, origin, search } = location || window.location;
if (hostname.endsWith('acrobat.adobe.com')) return `${origin}/dc-shared/libs`;
if (!(hostname.includes('.hlx.') || hostname.includes('.aem.') || hostname.includes('local'))) return prodLibs;
if (!['.aem.', '.hlx.', '.stage.', 'localhost', '.da.'].some((i) => hostname.includes(i))) return prodLibs;
const branch = new URLSearchParams(search).get('milolibs') || 'main';
if (branch === 'local') return 'http://localhost:6456/libs';
if (branch === 'main' && hostname.includes('.stage.')) return prodLibs;
const env = hostname.includes('.hlx.') ? 'hlx' : 'aem';
return branch.includes('--') ? `https://${branch}.${env}.live/libs` : `https://${branch}--milo--adobecom.${env}.live/libs`;
})();
Expand All @@ -29,7 +30,7 @@ export const [setUnityLibs, getUnityLibs] = (() => {

export function decorateArea() {}

const miloLibs = setLibs('/libs');
const miloLibs = setLibs(`${window.location.origin}/libs`);
Copy link
Copy Markdown
Contributor Author

@nkthakur48 nkthakur48 Apr 26, 2026

Choose a reason for hiding this comment

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

Explanation for this change:
unitylibs/scripts/utils.js is consumed cross-origin — when a project like da-cc loads it from a custom unity branch, the file is served from https://my-branch--unity--adobecom.aem.live. In ES modules, a root-relative path like /libs resolves against the module's origin, not the page's origin. So import('/libs/utils/utils.js') was hitting https://my-branch--unity--adobecom.aem.live/libs/utils/utils.js - a 404.

This only became visible after the stage fix: on .aem./.hlx. hosts, setLibs already returns an absolute Milo URL, so module origin doesn't matter. On stage with branch === 'main', it now falls through and returns the relative prodLibs = '/libs', which exposed the bug.

Passing ${window.location.origin}/libs instead makes prodLibs an absolute URL anchored to the page's origin, so the import always resolves correctly regardless of where the module was loaded from.


const {
createTag, getConfig, loadStyle, loadLink, loadScript, localizeLink, loadArea,
Expand Down
Loading