test: check the Better Auth packages stay in one server bundle - #8
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. WalkthroughVite SSR now externalizes ChangesSSR externalization
Priority: ➖ Normal Change: Bug fix Merge Risk: ⚪ Minimal · up to Externalizing the shared better-auth package is intended to let provider callbacks resume the initiating OAuth request. No actionable merge-blocking risk is evident; proceed with normal checks. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 2 systems. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signing in to an application through this provider dropped the caller when the person was not already signed in here: after authenticating with Google or PoliNetwork APS they landed on this app's home page instead of returning to the application that sent them. The cause was two copies of Better Auth in the server bundle, each with its own keys for the request state that carries the pending authorization across the provider redirect. The fix landed in #9, which bundles every `better-auth` and `@better-auth/*` package together and fails the build if any request state is duplicated. That check only runs on a build, so add a unit test that reads the Better Auth packages from package.json and checks that `ssr.noExternal` bundles each of them and their subpaths, and that none is marked external. It fails on the old config and on keeping `better-auth` external. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
d84a093 to
fc6e0c0
Compare
lorenzocorallo
left a comment
There was a problem hiding this comment.
Rebased on #9, which fixed the same bug the other way round. The original ssr.external change would have brought the bug back next to #9's setting, so it's dropped. What's left is a test that checks every Better Auth package in package.json is kept in the server bundle. It fails on both old configs.
What this PR is now
This PR started as a fix for the same bug as #9: when someone who was not already signed in here signed in to an application through this provider, they authenticated with Google or PoliNetwork APS and then landed on this app's home page, instead of going back to the application that sent them.
#9 fixed it first, in the opposite way to this PR, and has been merged. This PR is now rebased on top of it and only adds a test for #9's setting.
Why the original change was dropped
The original change kept
better-authout of the Vite server bundle (ssr.external: ["better-auth"]). It fixed the bug, but:better-auth/tanstack-startimports@tanstack/react-start/server. Cookies still worked only because TanStack happens to keep its request store on a global key.ssr.noExternal, it brings the bug back.externalwins forbetter-auth, and the OAuth plugin's own request state ends up in two copies. I checked this by building with both settings: fix: keep one Better Auth instance so provider sign-in returns to the app #9's build check fails.So only one of the two could land, and #9's approach is the one that works with TanStack Start instead of against it.
What this PR adds
vite.config.test.tsreads everybetter-auth/@better-auth/*package frompackage.jsonand checks thatssr.noExternalbundles each of them and their subpaths, and that none is marked external.#9's
scripts/check-server-bundle.mjscatches a duplicate in the built output, but only when you run a build. This test catches the setting that causes it undervp test, without building. It fails on the oldmainconfig and on this PR's original config.Checks
vp check: clean.vp test: 46 passed.vite.config.tsfrom before fix: keep one Better Auth instance so provider sign-in returns to the app #9 and with the originalssr.externalversion of this PR.🤖 Generated with Claude Code