[MMM] Fix 500 Internal Server Error when toggling manifest drawer#5801
[MMM] Fix 500 Internal Server Error when toggling manifest drawer#5801
Conversation
Fix normalizePath duplicating query params for external URLs. Commit 97b9337 added ${search} to the return, which is correct when path is stripped to pathname (AEM/HLX/adobe origins), but duplicated params for external URLs where path retains the full URL. Split return logic on isKnownOrigin: known origins reconstruct from pathname+search+hash; external URLs pass through via new URL(). Add null guard in mmm.js toggleDrawer to prevent destructure-of-null crash when fetchData returns null. Add unit tests for external URL normalization. Made-with: Cursor
|
Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
Commits
|
| path = isFederal ? getFederatedUrl(path) : path; | ||
| return `${path}${search}${hash.replace(mepHash, '')}`; | ||
| if (isKnownOrigin) { | ||
| return `${path}${search}${hash.replace(mepHash, '')}`; |
There was a problem hiding this comment.
Not sure we are addressing the case where path has search already. if it does, we are going to append search again, which is what is breaking mmm currently. I believe what was meant to be used is pathname?
There was a problem hiding this comment.
Good question. This line (130) only runs when isKnownOrigin is true, which means path has already been reassigned to just pathname on line 121. So appending ${search} here is re-attaching the query params to the stripped pathname, not duplicating them.
The case you're describing (where path retains the full URL) is handled just below on lines 132-134, in the !isKnownOrigin branch. There we reconstruct via new URL(path) which preserves existing query params without appending anything.
Summary
Toggling any page/manifest drawer on mmm page (i.e., clicking ".mmm-trigger" button) triggers a 500 Internal Server Error from the lambda API, followed by an uncaught TypeError: Cannot destructure property 'page' of 'mepConfig' as it is null. This update prevents normalizePath from duplicating query params on external URLs while preserving the existing entitlements param-retention behavior for known origins.
Root Cause
#5450 added ${search} to the return in normalizePath to fix entitlement sheet parameters not being retained. This works correctly for AEM/HLX/adobe/localhost URLs where path is reassigned to just pathname, but for external URLs (like the lambda API), path is never reassigned and still contains the full URL with query params. Appending ${search} duplicates them. The server receives a malformed URL and returns 500. fetchData returns null, which propagates to getMepPopup(null, true) where destructuring null throws.
Steps to QA Using the Before and After Test URLS below:
Expected Results: Manifest content is retrieved and displayed
Actual Results: spinner loads and 500 error thrown in console.
Resolves: MWPW-192357
Test URLs: