Repository navigation
Conversation
🦋 Changeset detectedLatest commit: f57bf8c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical "React is not defined" ReferenceError that occurred in CJS server builds introduced in version 6.3.10. The issue stemmed from TypeScript's import-elision removing the import React from 'react' statement because React was only referenced in a string injected by rollup's replace plugin after TypeScript compilation, not in any actual TypeScript expression.
Changes:
- Replaced the
__IS_RSC__build-time constant with a direct TypeScript expressiontypeof React.createContext === 'undefined'to prevent import elision - Updated rollup configurations to replace the entire expression string with
falsein browser/standalone/native builds - Removed
__IS_RSC__declarations from test globals since it's no longer a build-time injected constant
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/styled-components/src/constants.ts | Changed IS_RSC from using __IS_RSC__ constant to direct expression checking React.createContext, ensuring React import is preserved |
| packages/styled-components/rollup.config.mjs | Updated all build configs (standalone, browser, native) to replace the expression string instead of __IS_RSC__ constant; server config correctly omits replacement for runtime check |
| packages/styled-components/src/test/globals.ts | Removed __IS_RSC__ global declarations no longer needed since IS_RSC is now a direct expression |
| .changeset/fix-rsc-react-not-defined.md | Added changeset documenting the fix and explaining the root cause |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…5667) TypeScript's import-elision removed `import React from 'react'` in constants.ts because React was never referenced in any TypeScript expression — only in the rollup replace string injected after TS ran. Write IS_RSC as a direct TS expression so the import is preserved. Use rollup-plugin-replace with `delimiters: ['', '']` (exact match) for browser/standalone/native builds to substitute the literal `false`, keeping dead-code elimination intact. Server build gets the correct runtime check at no extra cost. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
TypeScript's import-elision removed
import React from 'react'in constants.ts because React was never referenced in any TypeScript expression — only in the rollup replace plugin's injected stringtypeof React.createContext === 'undefined'which ran after TS.Fix: write IS_RSC as a direct TS expression so the import is preserved. Browser/standalone/native builds replace the whole expression with the literal
falsevia rollup replace, keeping dead-code elimination intact.Fixes #5667