Repository navigation
fix!: externalize @base-ui/react so packages share one instance - #305
Merged
Merged
Conversation
@base-ui/react was missing from `baseExternal` in vite.config.ts, so rollup followed into it and inlined it — along with @base-ui/utils, @floating-ui/core, @floating-ui/react-dom, reselect, and use-sync-external-store — into every consuming package's dist. Beyond the size cost, each package shipped its own module instance of Base UI's context modules (TooltipRootContext, TooltipProviderContext, DirectionContext, FloatingTree). Two copies of a module mean two React.createContext() calls and two distinct context objects, so a provider rendered from one package's copy could not be read by a component resolving another's — composing across @uiid/* packages could silently fail to share state. Externalizing @base-ui/react is the half that does the work; the manifest change only keeps installs correct alongside it. Measured, from a forced clean rebuild: buttons 712K -> 160K forms 2968K -> 1808K indicators 572K -> 464K layout 360K -> 312K overlays 1540K -> 624K total 7388K -> 4604K (-2784K, 416 files) All four duplicated context modules now resolve to a single physical copy under node_modules/.pnpm, shared by all eight packages. BREAKING CHANGE: @base-ui/react moves from dependencies to peerDependencies on @uiid/buttons, forms, indicators, interactive, layout, lists, overlays, and tables. Consumers must install @base-ui/react themselves. This is deliberate — it is what guarantees a single deduplicated instance. Refs #304
Contributor
|
🏷️ Auto-labeled this PR: |
Contributor
Size report (affected packages)
Checked 11 affected package(s). Unchanged packages were not rebuilt. |
This was referenced Aug 20, 2026
adamfratino
added a commit
that referenced
this pull request
Aug 20, 2026
Five minor releases (1.3.0 -> 1.7.0, Feb to Aug 2026) across the 27 @base-ui/react modules this repo uses. Of the three breaking changes declared upstream, only one reaches us: `Drawer` was unmarked as preview in 1.3.0, renaming the namespace export `DrawerPreview` -> `Drawer`. 1.7.0 ships no deprecated alias, so the rename is mandatory — the 11 imports under packages/overlays/src/drawer/subcomponents all alias to `BaseDrawer`, so only the import specifier changes. The other two (`sanitizeValue()` -> `normalizeValue()`, `OTPFieldPreview` -> `OTPField`) touch APIs this repo does not use. Two undeclared behaviour changes did reach our tests: - Accordion lost roving focus in 1.6.0 (mui/base-ui#4965), following the APG which no longer recommends it (w3c/aria-practices#3434). Arrow keys no longer move focus between triggers; Tab does. The test now covers both. - 1.7.0 appends an invisible Word Joiner (U+2060) to Combobox/Autocomplete empty state text for ~200ms so Safari VoiceOver announces the polite live region. Exact-string matching broke on the marker; the assertion now matches loosely. Neither is a defect in this repo — both are upstream corrections our tests were pinning to the old behaviour. Verified: 481 tests pass, 17/17 build tasks including docs prerender, all size budgets green (aggregate 291.27 -> 295.71 kB), format and lint clean. The externalization from #305 still holds — no base-ui bundled in any dist. BREAKING CHANGE: the @base-ui/react peer range moves from ^1.2.0 to ^1.7.0. Consumers on 1.2.x-1.6.x must upgrade. Accordion triggers are no longer a roving focus group — arrow keys no longer move focus between them, per current APG guidance. Closes #303
11 tasks
adamfratino
added a commit
that referenced
this pull request
Aug 24, 2026
#305 promoted /^@base-ui\/react(\/|$)/ into baseExternal, which covers both the bare specifier and subpath imports. The per-package entries in indicators, interactive, layout, lists, overlays, and tables have been dead config ever since. buttons and forms were further out of date, listing /^@base-ui-components\// — the pre-rename scope, which is not installed in any manifest and imported by no source file. Verified as a no-op: after deleting every dist and rebuilding all 17 tasks from scratch, no package emits dist/node_modules, base-ui remains a bare import wherever it is used, and every pnpm size figure is unchanged.
adamfratino
added a commit
that referenced
this pull request
Aug 24, 2026
…tive (#308) * fix(ui): externalize @dnd-kit and react-resizable-panels from interactive @uiid/interactive was the last package emitting a dist/node_modules directory, vendoring six modules (144K unminified) that a consumer cannot dedupe, patch, or security-update. These are externalized but stay ordinary `dependencies` rather than becoming `peerDependencies`. @base-ui/react needed a peer because eight packages inlined it and produced duplicate React contexts; nothing here holds context shared across packages, and @dnd-kit/* and react-resizable-panels have exactly one consumer. Keeping them as regular dependencies means consumers install nothing extra — notably @uiid/tables, which depends on @uiid/interactive only for Menu and would otherwise inherit five unmet drag-and-drop peers. Also drops two dead entries: the react-medium-image-zoom dependency (imported nowhere in the repo) and the /^embla-carousel/ external (no package depends on embla). * chore(repo): drop redundant per-package base-ui externals #305 promoted /^@base-ui\/react(\/|$)/ into baseExternal, which covers both the bare specifier and subpath imports. The per-package entries in indicators, interactive, layout, lists, overlays, and tables have been dead config ever since. buttons and forms were further out of date, listing /^@base-ui-components\// — the pre-rename scope, which is not installed in any manifest and imported by no source file. Verified as a no-op: after deleting every dist and rebuilding all 17 tasks from scratch, no package emits dist/node_modules, base-ui remains a bare import wherever it is used, and every pnpm size figure is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@base-ui/reactwas missing frombaseExternalinvite.config.ts, so rollup followed into it and inlined it — along with@base-ui/utils,@floating-ui/core,@floating-ui/react-dom,reselect, anduse-sync-external-store— into every consuming package'sdist.Closes #304
The defect, not just the bloat
Each package shipped its own module instance of Base UI's context modules. Two copies of a module mean two
React.createContext()calls and two distinct context objects, so a provider rendered from one package's copy could not be read by a component resolving another's — composing across@uiid/*packages could silently fail to share state.After this change, all eight packages resolve to a single physical copy under
node_modules/.pnpm:TooltipRootContextTooltipProviderContextDirectionContextFloatingTreeMeasured, from
turbo run build --forceon a cleareddistformsoverlaysbuttonsindicatorslayoutEmitted output now carries a bare external import:
Changes
/^@base-ui\/react(\/|$)/tobaseExternal— a regex, not a bare string, so deep subpath imports like@base-ui/react/drawermatch@base-ui/reactfromdependenciestopeerDependencies(^1.2.0) across the eight consuming packages, with an exact1.2.0devDependencyso in-repo builds, types, and tests still resolveThe
baseExternalchange is the half that does the work — moving a dependency topeerDependencieson its own does not shrink anything. The manifest change just keeps installs correct alongside it.Deviation from the issue
The issue proposed
peerDependenciesMeta. I skipped it deliberately: the repo's existing precedent forreact/react-domis peer + dev with no meta, and marking@base-ui/reactoptional would be false — these components cannot render without it.The version pin stays at
1.2.0so this stays orthogonal to #303.Two checklist items from the issue that cannot pass as written
1. "No
node_modules/directories remain under anypackages/*/dist." Not achievable here.interactivestill emitsdist/node_modulescontaining@dnd-kit/core,@dnd-kit/modifiers,@dnd-kit/sortable,@dnd-kit/utilities,@dnd-kit/accessibility, andreact-resizable-panels. Same class of problem, different dependency set — out of scope for this change, and tracked separately in #306 (where the case is notably weaker: single consumer, so no duplicated contexts). Zero@base-ui/reactremains bundled anywhere, which is the goal that matters here.2. "A cross-package composition case works." Neither the test suite nor Storybook can verify this:
vitest.config.tsandapps/storybook/.storybook/main.tsboth alias@uiid/*to source, where only one base-ui instance ever existed. The duplicate-context bug was exclusively a property of the builtdistartifacts, so no unit test could have reproduced it and none can prove the fix.apps/docsis the only surface that consumes built output (no aliases,dependsOn: ["^build"]). It builds and prerenders/overlays/dialog,/overlays/drawer,/overlays/popover,/overlays/toast, and/overlays/tooltipas static pages — real SSG execution against the externalized output. That is meaningful partial evidence, but a deliberate composition repro against built packages would still be worth doing by hand.Verification
/^@base-ui\/react(\/|$)/present inbaseExternal— one line invite.config.tspeerDependencies+devDependencies; diff is 1 removal / 2 additions each, no reformatting@base-ui/reactbundled in anypackages/*/distdistcarries bare@base-ui/react/*importspnpm installreports no unmet@base-ui/reactpeerpnpm test:run— 480 passed, 2 skipped, 42 filespnpm run build— 17/17 tasks, includingdocs:buildpnpm size— all packages under budgetpnpm run format:checkclean;pnpm run lintreports only pre-existing warnings in untouched filesNote on
pnpm sizeNumbers are largely unchanged, and should be.
size-limitmeasures "with all dependencies", so it resolves and walks into base-ui either way. The win is in the published artifacts: consumers bundle base-ui once instead of once per@uiid/*package they install.