-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Components: Add eslint to prevent SSR breakage #42248
Conversation
Size Change: -57 B (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
const { clearTimeout, setTimeout } = | ||
typeof window !== 'undefined' ? window : {}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that this way is incorrect, but it is harder to programmatically check for safety (plus the timeout functions become an any
type in TS).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to have a lint rule that can prevent this from happening in the future. I've tested that the lint errors appear correctly: they weren't appearing for me in VS Code, but the lint-js
command works great:
npm run lint-js packages/components/src/resizable-box/resize-tooltip/utils.ts
It's probably just my editor setup.
I also double-checked that FocalPointPicker
, FormTokenField
and ResizableBox
still work correctly using storybook.
What?
Adds
eslint-plugin-ssr-friendly
to the Components package so we can do some basic checks for unsafe access of DOM globals.Why?
There have been some reports of breakage in SSR environments (#38400), and a sweep of the package codebase surfaced two more instances of unsafe
window
access.How?
The eslint plugin isn't perfect, but it will surface the more obvious breakage points, such as accessing DOM globals in module scope, or at the root level of a functional component (i.e. obviously not in a
useEffect
).Testing Instructions
npm run lint-js