MWPW-191059: Switch Studio preview from Odin to Freyja v2#741
MWPW-191059: Switch Studio preview from Odin to Freyja v2#741Axelcureno wants to merge 22 commits intomainfrom
Conversation
|
Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
|
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (62.50%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #741 +/- ##
==========================================
+ Coverage 87.22% 87.23% +0.01%
==========================================
Files 206 206
Lines 61740 61759 +19
==========================================
+ Hits 53851 53876 +25
+ Misses 7889 7883 -6
... and 4 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
…k in internalFetch
…nchmark tool for Freyja vs Odin comparison
…ble proxy port freyja-bench.html: browser-based latency tool comparing Freyja v2 vs Odin, token injected via sessionStorage (never URL params) proxy-server.mjs: PROXY_PORT env var support so proxy can run on non-8080 ports
Automatically extract and persist the IMS access token to sessionStorage.masFreyjaToken when IMS completes initialization. This ensures Freyja requests have the required authentication token immediately, preventing 403 Forbidden responses and unnecessary fallback to Odin Preview. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Move token caching from imsReady() to imsSignedIn() to ensure the token is cached only after the user is confirmed to be signed in, not just when IMS initializes. This ensures we have a valid, authorized token before attempting to use it. Previously: Token cached during IMS initialization, may be invalid Now: Token cached only after isSignedInUser() returns true Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Update fragment-client.js to use Freyja preview endpoint (localhost:9006) when a Freyja token is provided, with fallback to Odin. - Pass Freyja token from sessionStorage through aem-fragment.js generatePreview() - In fragment-client.js previewFragment(), check for freyjaToken in context - If token available: use Freyja endpoint and add Authorization header - If no token: fall back to Odin (existing behavior) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The DEFAULT_HEADERS containing the Authorization token was being set on the main context but lost during structuredClone when creating initContext for transformers. This caused fetch requests to Freyja to fail with 403 Forbidden. The fix preserves DEFAULT_HEADERS when creating initContext so the Authorization header is passed through the entire pipeline. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Replace hardcoded localhost:9006 with FREYJA_PREVIEW_URL constant pointing to the production Freyja AEM Cloud instance: https://preview-p22655-e59433.adobeaemcloud.com/adobe/contentFragments Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
npeltier
left a comment
There was a problem hiding this comment.
results look promising but:
- i would make authToken part of the preview configuration, as it's only for preview,
- io common fetch should not be odin specific (it's used with other hosts), nor preview specific, i would remove the fallback all together, and just make switch from one to the other easy enough,
- please add tests URLs so we can test your change (not sure how easy it is)
- don't forget this should be working on aem.page URLs in milo as well! right now it's only considering studio,
- please move benchmarks to a dedicated place, leaving fragment-client.js to what it does
…lidate auth under preview - Move authToken under preview namespace (preview.authToken) - Remove Odin fallback logic from internalFetch - Remove compareBackends benchmark from fragment-client.js - Move freyja-bench.html to studio/bench/ - Fix prettier formatting in ims.js
|
Please address formatting issues and improve code coverage. |
| @@ -0,0 +1,703 @@ | |||
| # Freyja v2 Preview Migration — Implementation Plan | |||
There was a problem hiding this comment.
Just curious: what AI agent/workflow did you use for these markdown files?
There was a problem hiding this comment.
https://github.com/obra/superpowers
Sorry, I will remove this and add a rule to not commit these files.
|
|
||
| const FRAGMENT_URL_PREFIX = 'https://odin.adobe.com/adobe/sites/fragments'; | ||
|
|
||
| const FREYJA_PREVIEW_URL = 'https://preview-p22655-e59433.adobeaemcloud.com/adobe/contentFragments'; |
There was a problem hiding this comment.
This is hardcoded to prod, what about supporting non-prod environments via aem.env?
There was a problem hiding this comment.
it's not really prod, but "preview" freyja
prod is odin.adobe.com
There was a problem hiding this comment.
Well, with prod I meant the prod environment in AEMaaCS speak. e59433 is prod, regardless if it's odin or freyja.
| @@ -0,0 +1,157 @@ | |||
| <!doctype html> | |||
There was a problem hiding this comment.
When trying to run this via https://mwpw-191059--mas--adobecom.aem.live/studio/bench/freyja-bench.html, all requests from the feature branch to freyja preview fail with CORS errors.
npeltier
left a comment
There was a problem hiding this comment.
what i meant by aem.page test link @Axelcureno is to have
https://main--cc--adobecom.aem.page/sa_ar/products/catalog?maslibs=mwpw-191059--mas--adobecom
working (which isn't atm)
|
also @Axelcureno, as discussed, performance is one part of the fix, we need to know how much time it takes from when content is changed on author to when content is previewed on that freyja server.
|
Freyja preview URL was hardcoded to the prod AEM environment (e59433). Adding freyjaUrl(env) helper in paths.js that maps qa/stage/prod to their respective AEM Cloud env IDs, and wiring it to the existing aem.env URL param in fragment-client.js so previews hit the correct Freyja instance.
yesil
left a comment
There was a problem hiding this comment.
@Axelcureno please see ODIN-949, let's connect if you need more details about my change request.
| /* c8 ignore next 10 */ | ||
| function poll() { | ||
| if (window.adobeIMS?.initialized) { | ||
| const token = window.adobeIMS?.getAccessToken?.()?.token; |
There was a problem hiding this comment.
ims.js is meant to be used for loggedin users and is not freyja token.
preview on acom stage should work for both logged-out and logged-in users, so we cannot use an access token.
| const fragmentClientUrl = this.getFragmentClientUrl(); | ||
| const { previewFragment } = await import(fragmentClientUrl); | ||
| const data = await previewFragment(this.#fragmentId, { | ||
| const freyjaToken = sessionStorage.getItem('masFreyjaToken'); |
There was a problem hiding this comment.
Please see ODIN-949, aem-fragment should work with the second url in the ticket and we will likely remove transformAuthorData from aem-fragment and just use transformPublishData for preview as well, happy to discuss in more detail.
There was a problem hiding this comment.
in this file, we need to switch the value of FRAGMENT_URL_PREFIX from https://odin.adobe.com/adobe/sites/fragments to https://odinpreview.corp.adobe.com/adobe/sites/fragments
In the case of preview.
Resolves https://jira.corp.adobe.com/browse/MWPW-191059
Migrate MAS Studio preview from Odin to Freyja v2 API. Benchmarking confirmed 41.4× speedup on worst-case (catalog all-hydrated: 15.7s → 380ms).
Changes:
preview.authToken)internalFetch— clean switch, no dual-pathcompareBackendsfrom fragment-client.js, move standalone bench tostudio/bench/masFreyjaTokenin sessionStorage for both Studio and aem.page contextsTest URLs:
Checklist: