Sidekick Preview: invalidate Worker cache + open the Next render#34
Merged
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-inpreviewedevent,POST /api/revalidate?slug=<path>thenwindow.openthe 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)./api/revalidateis now unauthenticated —REVALIDATE_SECRETis 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_SECRETcan be removed from the Worker + GitHub secrets since it's now unused.Where it fires / caveats
scripts.js, which runs on the classic*.aem.pagepreview pages — so it fires when Preview/Reload is clicked there, not from inside the DA editor (our code isn't in that tab).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 EDSrepository_dispatch).window.openafter theawaitmay be caught by a popup blocker on first use.Verified
Lint + build pass (
/api/revalidatecompiles). Can't drive the Sidekick extension from here — to test: on a…aem.pagepage with the Sidekick, click Preview and confirm aPOST /api/revalidatefires (Network tab) and a freshnxtjs.pagetab opens.🤖 Generated with Claude Code