Skip to content

refactor [NT-3230]: Use shared Preview Module in Web Preview Panel#314

Open
Felipe Mamud (fmamud) wants to merge 5 commits into
mainfrom
NT-3230-preview-panel
Open

refactor [NT-3230]: Use shared Preview Module in Web Preview Panel#314
Felipe Mamud (fmamud) wants to merge 5 commits into
mainfrom
NT-3230-preview-panel

Conversation

@fmamud

Copy link
Copy Markdown
Contributor

Summary

  • Replace the Web Preview Panel's inline override-management code with the shared PreviewOverrideManager from @contentful/optimization-core/preview-support, aligning the Web panel with the React Native SDK and iOS JSC bridge that already consume the same module.
  • Audience On/Off toggles now route through activateAudience/deactivateAudience, so audience-qualification snapshots and reset semantics match across platforms.
  • Variant pickers route through setVariantOverride; the panel reset button routes through resetAll; per-audience Default clears via resetAudienceOverride.
  • The web-only applyChangeOverrides (inline-variable → Variable changes) stays in the panel package — the shared module doesn't model the changes signal. It runs both as a state interceptor (on API refreshes) and synchronously from onOverridesChanged (on user clicks), so signals.changes and signals.selectedOptimizations always update in lockstep.
  • localStorage persistence is preserved by subscribing to onOverridesChanged; overrides loaded from storage are hydrated into the manager on attach so first-render selections still reflect the prior session.

Test plan

Validation:

  • pnpm typecheck — green across all packages
  • pnpm lint — clean
  • pnpm --filter @contentful/optimization-web-preview-panel build — succeeds, all bundle sizes under budget (umd 35.7k/38.5k, mjs 24.2k/26.5k, cjs 25.0k/27.5k gzip)
  • pnpm --filter @contentful/optimization-core test:unitPreviewOverrideManager coverage stays at 100%

End-to-end (against the web-sdk reference app + mock server):

  • pnpm implementation:run -- web-sdk test:e2e (Playwright preview-panel.spec.ts)
    • Panel attaches and drawer toggles
    • Per-experience variant override updates rendered content + getFlag
    • Audience search/filter
  • Audience-switch path (probed manually with a temporary spec):
    • On flips every experience under the audience to Variant 1
    • Off flips every experience under the audience to Baseline
    • Default clears the audience's overrides; natural qualification returns
  • localStorage persistence — Baseline override survives a hard reload; Reset Profile clears __ctfl_opt_preview_overrides__ and __ctfl_opt_preview_defaults__
  • Non-boolean inline-variable flags (json, number, plain-text) flip on Baseline/Variant 1 picks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we maybe migrate changes overrides to the Preview Support package, so we could similarly share that functionality with mobile (when we have someone who wants to make changes to mobile code 😅)?

@fmamud

Copy link
Copy Markdown
Contributor Author

Should we maybe migrate changes overrides to the Preview Support package, so we could similarly share that functionality with mobile (when we have someone who wants to make changes to mobile code 😅)?

done in 578c91b.

Also, I've considered making those changes wiring into PreviewOverrideManager itself, but it pushed the Web Preview Panel UMD ~12 kB gzip over budget (34.9 became 46.4, budget was 38.5). So I've done only the helper one to be right.

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.

2 participants