Move shared React contexts into dedicated modules#7939
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
Refactors @primer/react internals by moving shared React Context objects (and Portal root registry helpers) into dedicated modules, keeping component implementation files focused on exporting components while updating internal consumers accordingly.
Changes:
- Added dedicated
*Context.tsmodules for Tooltip/TooltipV2, Dialog, RadioGroup, ActionList Group, and Portal. - Extracted Portal root registry/default-root management into
Portal/portalRoot.tsand updated Portal + stories to use it. - Updated internal imports (e.g.,
IconButton,ActionMenu,ActionListconsumers) to reference the new modules.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/TooltipV2/TooltipContext.ts | New module housing TooltipV2 context. |
| packages/react/src/TooltipV2/Tooltip.tsx | Uses extracted TooltipV2 context module instead of defining it inline. |
| packages/react/src/Tooltip/TooltipContext.ts | New module housing Tooltip (v1) context. |
| packages/react/src/Tooltip/Tooltip.tsx | Uses extracted Tooltip (v1) context module instead of defining it inline. |
| packages/react/src/RadioGroup/RadioGroupContext.ts | New module housing RadioGroup context. |
| packages/react/src/RadioGroup/RadioGroup.tsx | Imports RadioGroup context from dedicated module. |
| packages/react/src/RadioGroup/index.ts | Re-exports RadioGroupContext from the new context module. |
| packages/react/src/Radio/Radio.tsx | Updates RadioGroupContext import to new module path. |
| packages/react/src/Portal/portalRoot.ts | New module for portal root registry + default portal root creation/registration. |
| packages/react/src/Portal/PortalContext.ts | New module housing Portal context. |
| packages/react/src/Portal/Portal.tsx | Uses extracted PortalContext + portal root helpers. |
| packages/react/src/Portal/Portal.features.stories.tsx | Updates story imports to use new PortalContext/portalRoot modules. |
| packages/react/src/Portal/index.ts | Preserves exports while sourcing PortalContext/registerPortalRoot from new modules. |
| packages/react/src/Dialog/DialogContext.ts | New module housing Dialog context. |
| packages/react/src/Dialog/Dialog.tsx | Imports DialogContext from dedicated module instead of exporting inline. |
| packages/react/src/Button/IconButton.tsx | Updates Tooltip/TooltipV2 context imports to new context modules. |
| packages/react/src/ActionMenu/ActionMenu.tsx | Updates DialogContext import to new module path. |
| packages/react/src/ActionList/Selection.tsx | Updates GroupContext import to new module path. |
| packages/react/src/ActionList/Item.tsx | Updates GroupContext import to new module path; updates TooltipV2 context import. |
| packages/react/src/ActionList/index.ts | Rewires GroupContext to come from new module and exposes it on ActionList. |
| packages/react/src/ActionList/GroupContext.ts | New module housing ActionList GroupContext. |
| packages/react/src/ActionList/Group.tsx | Imports GroupContext from dedicated module instead of defining/exporting inline. |
Copilot's findings
- Files reviewed: 22/22 changed files
- Comments generated: 0
Closes #
No linked issue.
Moves shared React contexts and Portal registry helpers out of component files so those component modules only export components.
Changelog
New
registerPortalRootand default portal root management.Changed
Removed
Rollout strategy
Testing & Reviewing
Review that context values moved to
{Name}Context.tsfiles and Portal registry behavior is unchanged.Merge checklist