Skip to content

[docs-infra] Restore build-only invariant throws via NEXT_RUNTIME guard#48475

Open
Janpot wants to merge 1 commit into
mui:masterfrom
Janpot:docs/guard-build-only-throws-next-runtime
Open

[docs-infra] Restore build-only invariant throws via NEXT_RUNTIME guard#48475
Janpot wants to merge 1 commit into
mui:masterfrom
Janpot:docs/guard-build-only-throws-next-runtime

Conversation

@Janpot
Copy link
Copy Markdown
Member

@Janpot Janpot commented May 5, 2026

Summary

PR #48365 introduced the mui/no-guarded-throw lint rule and removed the if (process.env.NODE_ENV !== 'production') wrappers around several invariant throws in docs components. Without the guard those throws now fire at client render time in production — a single bad config (missing manualCard header, overly long banner, invalid demo options, missing productIdentifier) hard-crashes the page in the browser instead of being caught at build time.

This restores the original semantics by guarding on process.env.NEXT_RUNTIME instead. The lint rule only matches NODE_ENV guards, so this passes lint. Next.js replaces NEXT_RUNTIME with undefined in client bundles, so the entire block is dead-code-eliminated from the browser — the check only runs during next build prerender and SSR.

PR mui#48365 introduced the `mui/no-guarded-throw` lint rule and removed the
`if (process.env.NODE_ENV !== 'production')` wrappers around several throws in
docs components, making those invariants throw at client render time.

Restore the original "fail at build, not in the browser" semantics by guarding
on `process.env.NEXT_RUNTIME` instead. The lint rule only matches `NODE_ENV`
guards, and Next.js replaces `NEXT_RUNTIME` with `undefined` in client
bundles, so the entire block is dead-code-eliminated from the browser.

Also drop the explicit `'mui/no-guarded-throw': 'error'` override from
`eslint.config.mjs` — the rule comes from the shared infra config.
@Janpot Janpot changed the title [docs] Restore build-only invariant throws via NEXT_RUNTIME guard [docs-infra] Restore build-only invariant throws via NEXT_RUNTIME guard May 5, 2026
@Janpot Janpot added the scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). label May 5, 2026
@code-infra-dashboard
Copy link
Copy Markdown

Deploy preview

https://deploy-preview-48475--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@Janpot Janpot changed the title [docs-infra] Restore build-only invariant throws via NEXT_RUNTIME guard [docs-infra] Restore build-only invariant throws via NEXT_RUNTIME guard May 5, 2026
@Janpot Janpot marked this pull request as ready for review May 5, 2026 07:23
@Janpot Janpot requested review from a team and oliviertassinari May 5, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant