Skip to content

Stop the consoles bundling two copies of the SDK - #210

Merged
bgrant0607 merged 2 commits into
mainfrom
fix-bundle-duplication
Aug 26, 2026
Merged

Stop the consoles bundling two copies of the SDK#210
bgrant0607 merged 2 commits into
mainfrom
fix-bundle-duplication

Conversation

@bgrant0607

Copy link
Copy Markdown
Member

Fixes the deployed rbac-manager, which throws on load:

Error: useAuth must be used within a <ConfigHubAuthProvider>

…with the provider plainly mounted in main.tsx.

Cause

Two copies of @confighub/react-auth in the bundle. The consoles alias webkit
to source, and webkit resolves its own bare imports from webkit/node_modules
while the console resolves the same names from its own. So AppShell got one
instance of the package and main.tsx got another — each with its own React
context, so the hook could not see the provider. From the source map:

../../../../webkit/node_modules/@confighub/react-auth/dist/index.js
../../node_modules/@confighub/react-auth/dist/index.js

The same split duplicated the whole MUI/emotion tree.

resolve.dedupe in each console's vite config fixes it.

Why it shipped

Nothing reported it. tsc passed, vite build passed, the container served the
bundle, and the dev server worked — Vite pre-bundles dependencies into a single
copy, so only a production build has the problem, and only its source map
records it
. My verification was dev-server and HTTP 200s; I never loaded a
production build in a browser.

So the check is the other half of this change:

  • scripts/check-bundle-dedupe.mjs reads the source map and fails when a package
    was resolved from more than one node_modules root. Ordinary nesting inside one
    root (npm resolving two versions of a transitive dep) is normal and ignored.
  • .github/workflows/js-apps.yml runs lint, test, build, and that check for
    webkit and all six consoles on every PR that touches them. There was no CI for
    the JS packages at all before this.

Removing the dedupe list from one console makes the check report 24 duplicated
packages, @confighub/react-auth among them — so it does catch the thing it is
named for.

Verification

Every console's production build loaded in a browser, plus the rbac-manager
container image, all rendering with no console errors — rather than trusting an
exit code.

🤖 Generated with Claude Code

https://claude.ai/code/session_01P9g7PRiXsoTGFMkzmeNgEJ

The deployed rbac-manager threw `useAuth must be used within a
<ConfigHubAuthProvider>` on load, with the provider plainly mounted in main.tsx.

There were two copies of @confighub/react-auth in the bundle. The consoles alias
webkit to source, and webkit resolves its own bare imports from
webkit/node_modules while the console resolves the same names from its own — so
AppShell got one instance of the package and main.tsx got another, each with its
own React context. The same split duplicated the whole MUI/emotion tree.

resolve.dedupe fixes it, but the reason this shipped is worth more than the fix:
nothing reported it. tsc passed, vite build passed, the container served, and the
dev server worked — Vite pre-bundles dependencies into a single copy, so only a
production build has the problem, and only its source map records it.

So the check is the other half of this change. scripts/check-bundle-dedupe.mjs
reads the source map and fails when one package was resolved from more than one
node_modules root, ignoring ordinary nesting within a root. Removing the dedupe
list from one console makes it report 24 duplicated packages, @confighub/react-auth
among them.

js-apps.yml runs lint, test, build, and that check for webkit and all six
consoles, on every PR that touches them.

Verified by loading every console's production build in a browser, and the
rbac-manager container image, rather than trusting an exit code.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P9g7PRiXsoTGFMkzmeNgEJ
configboard imported `@mui/icons-material/AddChart`; the file is `Addchart.d.ts`.
macOS resolves it anyway because its filesystem is case-insensitive, so this only
fails on Linux — and no CI had ever built these apps on Linux.

Found by the JS console workflow added in this change, on its first run.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P9g7PRiXsoTGFMkzmeNgEJ
@bgrant0607
bgrant0607 merged commit 8f1d694 into main Aug 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant