Skip to content

Sidekick Preview: invalidate Worker cache + open the Next render#34

Merged
lamontacrook merged 2 commits into
mainfrom
sidekick-next-preview
Jul 6, 2026
Merged

Sidekick Preview: invalidate Worker cache + open the Next render#34
lamontacrook merged 2 commits into
mainfrom
sidekick-next-preview

Conversation

@lamontacrook

@lamontacrook lamontacrook commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What

Hooks the AEM Sidekick's Preview so that clicking it invalidates the Worker's cache for that page and then opens the (now fresh) Next.js render on nxtjs.page.

  • scripts.js — on the built-in previewed event, POST /api/revalidate?slug=<path> then window.open the Next render.
  • app/api/revalidate/route.js — made browser-callable: unauthenticated, open CORS (OPTIONS + Access-Control-Allow-Origin: *), and accepts the slug as a query param (JSON body still works for the existing workflow).

⚠️ Security posture change (as agreed)

/api/revalidate is now unauthenticatedREVALIDATE_SECRET is no longer enforced. This is required for a client-side (Sidekick) caller, which can't hold a secret. Revalidation only forces a cache refresh (no data exposure); the worst case is someone triggering extra origin fetches. REVALIDATE_SECRET can be removed from the Worker + GitHub secrets since it's now unused.

Where it fires / caveats

  • The listener is in scripts.js, which runs on the classic *.aem.page preview pages — so it fires when Preview/Reload is clicked there, not from inside the DA editor (our code isn't in that tab).
  • The prod Worker reads aem.live (EDS_ORIGIN), so a preview invalidation re-fetches the current live content. This is fully meaningful only for a Worker pointed at the preview origin; on prod it matters at publish time (already wired via EDS repository_dispatch).
  • window.open after the await may be caught by a popup blocker on first use.

Verified

Lint + build pass (/api/revalidate compiles). Can't drive the Sidekick extension from here — to test: on a …aem.page page with the Sidekick, click Preview and confirm a POST /api/revalidate fires (Network tab) and a fresh nxtjs.page tab opens.

🤖 Generated with Claude Code

Listen for the AEM Sidekick `previewed` event in scripts.js and open the same
path on the Next Worker (nxtjs.page) in a reused tab. The built-in Preview shows
the classic Edge Delivery render; this surfaces the actual production render
alongside it. No sidekick plugin config needed — uses the built-in event.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@aem-code-sync

aem-code-sync Bot commented Jul 6, 2026

Copy link
Copy Markdown

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run all PSI checks
  • Re-run failed PSI checks
  • Re-sync branch
Commits

On the Sidekick `previewed` event, POST /api/revalidate?slug=<path> to clear the
page's cache, then open the fresh Next render. To make the endpoint callable from
the browser, /api/revalidate is now unauthenticated with open CORS and accepts
the slug as a query param (JSON body still works for the workflow).

Security note: revalidation is now open — it only forces a cache refresh (no data
exposure), worst case is extra origin fetches. REVALIDATE_SECRET is no longer
enforced.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lamontacrook lamontacrook changed the title Sidekick: open the Next.js render when Preview is clicked Sidekick Preview: invalidate Worker cache + open the Next render Jul 6, 2026
@lamontacrook
lamontacrook merged commit ad23e35 into main Jul 6, 2026
1 of 2 checks passed
@lamontacrook
lamontacrook deleted the sidekick-next-preview branch July 6, 2026 22:43
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.

1 participant