Repository navigation
fix: don't let the menu fetch overwrite a host-supplied menu - #147
Open
isaaclombardssw wants to merge 1 commit into
Open
isaaclombardssw wants to merge 1 commit into
isaaclombardssw wants to merge 1 commit into
Conversation
useMenuItems fired an unconditional fetch on mount, so a host that passed menuBarItems had its menu replaced by whatever /api/get-megamenu returned. That endpoint sits behind an in-process cache, a CDN cache and a 4h browser cache, so SSW.Website could deploy a menu change, serve it correctly in its HTML, and still show the old menu once hydration finished. Skip the fetch when the host supplies the menu. Hosts that pass nothing are unaffected. Co-Authored-By: Claude Opus 5 (1M context) <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.
Problem
useMenuItemsfires an unconditional fetch on mount, so a host that passesmenuBarItemsgets its menu replaced by whatever/api/get-megamenureturns:That endpoint sits behind three caches — a 60-min in-process cache in the route, a CDN cache, and
max-age=14400in the browser. So SSW.Website can deploy a menu change, serve it correctly in its HTML, and still show the old menu the moment hydration finishes.Live example today: SSW.Website PR #4981 added "Claude Training Workshop" and removed "Azure Super Skills".
view-source:https://www.ssw.com.au/has the new menu; the rendered page has the old one, because the CDN is still holding a copy of the API response captured 54 minutes before that PR merged.Fix
Skip the fetch when the host already supplied the menu — one source of truth instead of two racing ones. Hosts that pass nothing (cross-site consumers) keep the existing behaviour unchanged.
This also delivers what the same-origin branch above it was added for: a PR preview slot now actually shows the menu that slot built with, instead of production's.
Testing
Verified locally with a
renderHooktest — fetch not called whenmenuBarItemsis supplied, still called and applied when it isn't. It passes with this change and fails without it.It isn't in this PR because
vitestcannot run in this repo at all onmain, for four unrelated reasons, and fixing them means a ~500-line lockfile diff that would bury a 9-line fix. Raising that separately. For reference:rollup-plugin-node-externalsinpluginsbreaks vitest's config resolution — needsapply: "build"jsdomisn't indevDependenciesvite.config.tspointssetupFilesatscripts/tests/setup.js; the file issetup.tsscripts/tests/setup.tsuses the pre-v6@testing-library/jest-domdefault import — needsimport * as matchersAlso worth knowing: with those fixed, the pre-existing
src/App.test.tsxfails. It assertsApp-headeranddisplay: flexon a<header>that has noclassName— leftover CRA boilerplate that has never matched this component. Left alone here.CI only runs
pnpm lint, so none of this shows up as red today.Shipping
publish.ymlpublishes on a GitHub release, so this needs a version bump + release cut after merge, then a follow-up PR in SSW.Website bumpingssw.megamenufrom4.14.0.Note this does not fix the current stale menu — that needs a CDN purge of
https://www.ssw.com.au/api/get-megamenu. This stops it recurring.🤖 Generated with Claude Code