-
Notifications
You must be signed in to change notification settings - Fork 190
Fix React 17 webpack build error for useInsertionEffect #744
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
Conversation
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…ertionEffect Co-authored-by: thebuilder <[email protected]>
commit: |
commit: |
|
@copilot tests are now failing for React 17: |
Co-authored-by: thebuilder <[email protected]>
... Fixed in commit 99b5cba. Changed the ternary to return |
|
@copilot the PR now fails because of a type error in React 17. |
Co-authored-by: thebuilder <[email protected]>
... Fixed in commit 043ac66. The issue was that TypeScript couldn't properly infer the type when accessing a property that doesn't exist in React 17 types. I've added proper type assertions to ensure the expression works correctly across all React versions (17, 18, and 19). |
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.
Pull request overview
This PR fixes a React 17 compatibility issue where Webpack fails to build due to attempting to resolve useInsertionEffect, which doesn't exist in React 17. The fix changes the detection pattern from optional property access to an in operator check with proper type assertions.
Changes:
- Updated
useOnInView.tsxto use theinoperator to check foruseInsertionEffectexistence before accessing it - Applied proper TypeScript type assertions to maintain type safety across React 17, 18, and 19
- Added deprecation notice in pnpm-lock.yaml for whatwg-encoding package
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/useOnInView.tsx | Modified useSyncEffect definition to use runtime property checking instead of compile-time property access, preventing Webpack from resolving non-existent exports in React 17 |
| pnpm-lock.yaml | Added deprecation notice for whatwg-encoding package (automated lockfile update) |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix React 17 compatibility - useInsertionEffect error ✅
Analysis
useInsertionEffectdoesn't exist in React 17export 'useInsertionEffect' (imported as 'React3') was not found in 'react'Plan
useOnInView.tsxto use a safer pattern for checkinguseInsertionEffectexistenceChanges Made
src/useOnInView.tsxto use theinoperator to check ifuseInsertionEffectexists before accessing it(React as typeof React & { useInsertionEffect: typeof React.useEffect })instead ofanyto access the property safelyas typeof React.useEffectto the entire expression to ensure correct type inference across all React versions"useInsertionEffect" in React3 ? React3.useInsertionEffect : void 0Security Summary
No security vulnerabilities were found in the changes made.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.