fix(react): enable React Compiler for hooks#8124
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🦋 Changeset detectedLatest commit: f9a6462 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 |
|
| '@primer/react': patch | ||
| --- | ||
|
|
||
| Hooks: Enable React Compiler optimization for hook utilities |
There was a problem hiding this comment.
@copilot be specific about the hooks changed.
There was a problem hiding this comment.
Updated in 73cd1b5 — changeset now lists each hook by name.
There was a problem hiding this comment.
@copilot I'm not a big fan of this approach. Let's find something better
There was a problem hiding this comment.
Totally open to a different approach here. The core problem is that these hooks expose a caller-supplied DependencyList which React Compiler can't track statically, so I reached for a manual comparison wrapper. What direction were you thinking? For example: dropping the dep-list override entirely, converting to a callback-based API, or something else? Happy to implement once the direction is clear.
Co-authored-by: joshblack <3901764+joshblack@users.noreply.github.com>
|
@copilot I'm not a big fan of the useDependencyList approach. Let's try something else |
Happy to change direction. Before I implement something, which of these would you prefer?
Or if you have a different approach in mind, let me know and I'll implement that. |
Follow up to the React Compiler migration work. This PR enables React Compiler for the remaining hook utilities under
packages/react/src/hooks.Changelog
New
Changed
Removed
useAnchoredPosition,useFocusTrap,useFocusZone,useMenuInitialFocus,useOnEscapePress,useResizeObserver, anduseSafeTimeout.Rollout strategy
This keeps the published API the same and updates our internal compiler compatibility for hooks.
Testing & Reviewing
Would love a review on the dependency tracking changes in the hook utilities, especially
useFocusTrapanduseAnchoredPosition, since those preserve existing dependency-list behavior while avoiding React Compiler skips.Verified with:
npm run buildnpm test -- --runnpm run type-checknpm run lintnpm run lint:cssnpm run format:diffpackages/react/node_modules/.bin/tsx script/react-compiler-migration-status.mtsMerge checklist