Skip to content

fix(routes): add resolveGlobals opt-out for automatic site globals (#292)#294

Open
JonasJesus42 wants to merge 1 commit into
mainfrom
issue-292
Open

fix(routes): add resolveGlobals opt-out for automatic site globals (#292)#294
JonasJesus42 wants to merge 1 commit into
mainfrom
issue-292

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Context

Closes #292.

Since v6.7.4 (commit 4fb2a98, "resolve site globals inside loadCmsPage server fn"), resolveSiteGlobals() was moved out of the withSiteGlobals() wrapper and into the loadCmsPage / loadCmsHomePage server 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-bundled blocks.gen.ts and silently dropped globals).

The side effect: sites that never used withSiteGlobals() (including the migration scaffold, which generates cmsRouteConfig without the wrapper) now have the CMS Site block — theme + global + pageSections — silently injected into every page. For lebiscuit, this rendered a Theme section whose toValue() emits bare oklch components, overriding the working :root hex fallbacks in app.css and breaking all custom colors site-wide (Tailwind v4 @theme { … var(--brand-…) } resolved to invalid CSS).

Approach — opt-out flag, default true

We 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 resolveGlobals flag to cmsRouteConfig / cmsHomeRouteConfig:

  • Default 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 empty siteGlobals, and :root CSS fallbacks are used.
cmsRouteConfig({ siteName: "…", defaultTitle: "…", resolveGlobals: false })

Implementation

  • loadCmsPageInternal(fullPath, resolveGlobals) gates the resolveSiteGlobals() call, falling back to an EMPTY_GLOBALS result that flows through the identical merge path.
  • The flag is threaded through both server functions' input. loadCmsPage still accepts a bare string (back-compat for direct callers) or { path, resolveGlobals }; loadCmsHomePage accepts { resolveGlobals }. It's included in the pageInflight dedup key.
  • Input parsing extracted into pure, unit-tested helpers: parseLoadCmsPageInput, parseLoadCmsHomePageInput.
  • withSiteGlobals() is unchanged (still a deprecated no-op).

Site-side note (lebiscuit — separate repo)

The malformed oklch output lives in lebiscuit's own Theme.tsx. With this PR, lebiscuit can either (a) set resolveGlobals: false to keep its :root fallbacks, or (b) fix toValue() to emit full oklch(...).

Tests

  • New src/routes/cmsRouteInput.test.ts (string back-compat, default-true, explicit-false) — passing.
  • Existing withSiteGlobals tests unchanged — passing.
  • tsc --noEmit clean; biome formatted.

🤖 Generated with Claude Code


Summary by cubic

Adds an opt-out resolveGlobals flag 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 injected Site/Theme on all routes and broke CSS fallbacks (addresses #292).

  • Bug Fixes

    • Gate resolveSiteGlobals() behind resolveGlobals in loadCmsPage and loadCmsHomePage; use empty globals when false.
    • Thread flag through cmsRouteConfig and cmsHomeRouteConfig; include in inflight dedup key; keep loadCmsPage string input back-compat.
    • Add parseLoadCmsPageInput and parseLoadCmsHomePageInput with tests.
  • Migration

    • To opt out: set resolveGlobals: false in cmsRouteConfig/cmsHomeRouteConfig.

Written for commit 9c874e4. Summary will update on new commits.

Review in cubic

)

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant