fix(routes): add resolveGlobals opt-out for automatic site globals (#292)#294
Open
JonasJesus42 wants to merge 1 commit into
Open
fix(routes): add resolveGlobals opt-out for automatic site globals (#292)#294JonasJesus42 wants to merge 1 commit into
JonasJesus42 wants to merge 1 commit into
Conversation
) Since v6.7.4, resolveSiteGlobals() runs unconditionally inside the loadCmsPage/loadCmsHomePage server functions (the #233 fix), silently injecting the CMS `Site` block (theme/global/pageSections) into every route — including sites that never opted in via withSiteGlobals(). For sites relying on :root CSS fallbacks (e.g. lebiscuit), an injected Theme section overrode those fallbacks and broke custom colors site-wide. Add a `resolveGlobals` flag to cmsRouteConfig / cmsHomeRouteConfig (default `true` — no behavior change for working sites or the migration scaffold). Set `false` to restore pre-6.7.4 behavior: globals are not resolved and the page carries empty siteGlobals. The flag is threaded through the server functions via their input (loadCmsPage still accepts a bare string for back-compat) and gates the resolveSiteGlobals() call, falling back to an EMPTY_GLOBALS result that flows through the same merge path. Input parsing is extracted into pure, unit-tested helpers (parseLoadCmsPageInput / parseLoadCmsHomePageInput). Co-Authored-By: Claude Opus 4.8 (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.
Context
Closes #292.
Since v6.7.4 (commit
4fb2a98, "resolve site globals inside loadCmsPage server fn"),resolveSiteGlobals()was moved out of thewithSiteGlobals()wrapper and into theloadCmsPage/loadCmsHomePageserver functions — where it runs unconditionally on every CMS route, regardless of whether the site opted in. This was done to fix #233 (SPA navigations saw an empty client-bundledblocks.gen.tsand silently dropped globals).The side effect: sites that never used
withSiteGlobals()(including the migration scaffold, which generatescmsRouteConfigwithout the wrapper) now have the CMSSiteblock —theme+global+pageSections— silently injected into every page. For lebiscuit, this rendered aThemesection whosetoValue()emits bareoklchcomponents, overriding the working:roothex fallbacks inapp.cssand breaking all custom colors site-wide (Tailwind v4@theme { … var(--brand-…) }resolved to invalid CSS).Approach — opt-out flag, default
trueWe cannot flip the default to off: post-6.7.4 the framework's intent is that globals auto-render, and the migration scaffold relies on it — turning it off by default would break every newly-migrated site whose Theme/Analytics/Wishlist globals now render correctly.
Instead, add a
resolveGlobalsflag tocmsRouteConfig/cmsHomeRouteConfig:true→ current behavior, no change for working sites or the scaffold.resolveGlobals: false→ restores pre-6.7.4 behavior: globals are not resolved, the page carries emptysiteGlobals, and:rootCSS fallbacks are used.Implementation
loadCmsPageInternal(fullPath, resolveGlobals)gates theresolveSiteGlobals()call, falling back to anEMPTY_GLOBALSresult that flows through the identical merge path.loadCmsPagestill accepts a bare string (back-compat for direct callers) or{ path, resolveGlobals };loadCmsHomePageaccepts{ resolveGlobals }. It's included in thepageInflightdedup key.parseLoadCmsPageInput,parseLoadCmsHomePageInput.withSiteGlobals()is unchanged (still a deprecated no-op).Site-side note (lebiscuit — separate repo)
The malformed
oklchoutput lives in lebiscuit's ownTheme.tsx. With this PR, lebiscuit can either (a) setresolveGlobals: falseto keep its:rootfallbacks, or (b) fixtoValue()to emit fulloklch(...).Tests
src/routes/cmsRouteInput.test.ts(string back-compat, default-true, explicit-false) — passing.withSiteGlobalstests unchanged — passing.tsc --noEmitclean; biome formatted.🤖 Generated with Claude Code
Summary by cubic
Adds an opt-out
resolveGlobalsflag to CMS routes so sites can disable automatic site globals injection; defaults to true to keep current behavior. Fixes the v6.7.4 regression that injectedSite/Themeon all routes and broke CSS fallbacks (addresses #292).Bug Fixes
resolveSiteGlobals()behindresolveGlobalsinloadCmsPageandloadCmsHomePage; use empty globals when false.cmsRouteConfigandcmsHomeRouteConfig; include in inflight dedup key; keeploadCmsPagestring input back-compat.parseLoadCmsPageInputandparseLoadCmsHomePageInputwith tests.Migration
resolveGlobals: falseincmsRouteConfig/cmsHomeRouteConfig.Written for commit 9c874e4. Summary will update on new commits.