Skip to content

SSR: actionable error when a component touches a browser global during render#15

Merged
shivamsn97 merged 1 commit into
mainfrom
fix/ssr-browser-global-error
Jul 7, 2026
Merged

SSR: actionable error when a component touches a browser global during render#15
shivamsn97 merged 1 commit into
mainfrom
fix/ssr-browser-global-error

Conversation

@shivamsn97

Copy link
Copy Markdown
Member

Evaluating window, document, or another browser-only global at render scope used to fail SSR with a bare "window is not defined" and a framework-internal traceback — no pointer to the offending page, no hint at the fix.

Such ReferenceErrors are now raised as BrowserGlobalRenderError with a plain-language explanation (browser globals don't exist during server rendering), the page's .pyxl source file, and the remedy: move browser-only code into useEffect or an event handler, or gate it behind a client-only pattern (linked to the Client components guide).

  • Development: the rich message appears on the error page, the overlay breadcrumb, and navigation-error JSON.
  • Production: HTTP bodies stay generic — the enriched message goes to the server log only.
  • Covers both buffered and streaming shell errors; the original exception is preserved as __cause__.
  • Unrelated ReferenceErrors and all other render errors flow through as the identical exception object (regression-tested, including near-miss identifier names).

Tests: 2336 passed, coverage 96.54%.

… SSR

A component evaluating window/document/etc. at render scope failed with
a bare 'window is not defined' and a framework-internal traceback —
no pointer to the user's file, no remedy. ReferenceErrors on browser-
only globals (module constant BROWSER_ONLY_GLOBALS) are now raised as
BrowserGlobalRenderError: a plain-language explanation that browser
globals don't exist during server rendering, the page's .pyxl source
file, and the remedy (useEffect / event handler / client-only gating,
pointing at the Client components guide). Dev gets the rich message on
the error page, overlay breadcrumb, and nav-error JSON; production
bodies stay generic — the enriched message goes to the server log only.
Covers buffered and streaming shell errors; unrelated render errors
flow through as the identical exception object.

Suite: 2208 passed, coverage 96.50%. Ruff clean.
@shivamsn97 shivamsn97 merged commit 9f49544 into main Jul 7, 2026
5 checks passed
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