Skip to content

MWPW-191059: Switch Studio preview from Odin to Freyja v2#741

Draft
Axelcureno wants to merge 22 commits intomainfrom
MWPW-191059
Draft

MWPW-191059: Switch Studio preview from Odin to Freyja v2#741
Axelcureno wants to merge 22 commits intomainfrom
MWPW-191059

Conversation

@Axelcureno
Copy link
Copy Markdown
Member

@Axelcureno Axelcureno commented Apr 3, 2026

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:

  • Switch preview endpoint from Odin to Freyja v2
  • Move authToken under preview namespace (preview.authToken)
  • Remove Odin fallback logic from internalFetch — clean switch, no dual-path
  • Remove compareBackends from fragment-client.js, move standalone bench to studio/bench/
  • Cache IMS token as masFreyjaToken in sessionStorage for both Studio and aem.page contexts
  • Conditional freyjaToken injection in aem-fragment.js

Test URLs:

Checklist:

  • Code follows project conventions
  • Tests pass locally (230 io/www + 1226 web-components)
  • Linter runs without errors
  • Tested on Before/After URLs
  • Verified aem.page preview works with IMS token

@aem-code-sync
Copy link
Copy Markdown

aem-code-sync bot commented Apr 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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 62.50000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.23%. Comparing base (66ef1ca) to head (1c0bd44).

Files with missing lines Patch % Lines
web-components/src/aem-fragment.js 0.00% 7 Missing ⚠️
web-components/src/ims.js 80.95% 4 Missing ⚠️
studio/src/mas-repository.js 75.00% 1 Missing ⚠️

❌ 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

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
studio/src/mas-repository.js 61.94% <75.00%> (+0.02%) ⬆️
web-components/src/ims.js 94.28% <80.95%> (-5.72%) ⬇️
web-components/src/aem-fragment.js 85.28% <0.00%> (-0.87%) ⬇️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 66ef1ca...1c0bd44. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Axelcureno and others added 14 commits April 3, 2026 12:40
…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>
Copy link
Copy Markdown
Contributor

@npeltier npeltier left a comment

Choose a reason for hiding this comment

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

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

@Axelcureno Axelcureno self-assigned this Apr 7, 2026
…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
@honstar
Copy link
Copy Markdown
Contributor

honstar commented Apr 10, 2026

Please address formatting issues and improve code coverage.

@@ -0,0 +1,703 @@
# Freyja v2 Preview Migration — Implementation Plan
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curious: what AI agent/workflow did you use for these markdown files?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

https://github.com/obra/superpowers
Sorry, I will remove this and add a rule to not commit these files.

Comment thread io/www/src/fragment/utils/paths.js Outdated

const FRAGMENT_URL_PREFIX = 'https://odin.adobe.com/adobe/sites/fragments';

const FREYJA_PREVIEW_URL = 'https://preview-p22655-e59433.adobeaemcloud.com/adobe/contentFragments';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is hardcoded to prod, what about supporting non-prod environments via aem.env?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's not really prod, but "preview" freyja
prod is odin.adobe.com

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

@npeltier npeltier left a comment

Choose a reason for hiding this comment

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

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)

@npeltier
Copy link
Copy Markdown
Contributor

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.
Once we do:

  • either it's acceptabe time (let's say < 10s),
  • either we need to mitigate with authors,
  • either we need to auto-publish to preview freyja when we save

@Axelcureno Axelcureno marked this pull request as draft April 13, 2026 20:31
@Axelcureno
Copy link
Copy Markdown
Member Author

We are blocked by product team who needs to make more changes to enable Freyja for us, so the PR is not yet ready for review. I will in the meantime address the comments. Once we are unblocked I will request reviews. @honstar @npeltier

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.
Copy link
Copy Markdown
Contributor

@yesil yesil left a comment

Choose a reason for hiding this comment

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

@Axelcureno please see ODIN-949, let's connect if you need more details about my change request.

Comment thread web-components/src/ims.js
/* c8 ignore next 10 */
function poll() {
if (window.adobeIMS?.initialized) {
const token = window.adobeIMS?.getAccessToken?.()?.token;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants