Fixes #8062
The bug#
When Vite's experimental.bundledDev (full bundle mode) is enabled, the client environment is driven by Rolldown's dev engine. Vite passes environment plugins into that build, but injectEnvironmentToHooks only wraps hooks listed in ROLLUP_HOOKS, and hotUpdate is not in that list. Rolldown therefore invokes hotUpdate with its own PluginContextImpl as this, which has no environment property, so the first line of the hook throws:
✘ Build error: Build failed with 1 error:
[plugin tanstack-start-core::server-fn:client]
TypeError: Cannot read properties of undefined (reading 'name')
at PluginContextImpl.hotUpdate (.../start-plugin-core/dist/esm/vite/start-compiler-plugin/plugin.js:183:53)
at plugin (.../rolldown/dist/shared/bindingify-input-options-C-Zsy1EG.mjs:1734:24)
The dev server does not crash: Rolldown swallows the throw into a build error, the rebuild fails, and the dev server serves stale output on every subsequent edit until restart. Fires on 100% of hot updates. Present in @tanstack/start-plugin-core 1.171.17 through 1.171.34.
Minimal repro (vite 8.2.1, one createServerFn, bundledDev: true): https://github.com/TIMTOMTOP/tanstack-hotupdate-repro
The fix#
Early-return when this.environment is absent. Optional chaining on the first read is not enough: finishHotUpdate() dereferences this.environment again later. Compiler invalidation under bundledDev already happens via watchChange (which Vite calls with the environment injected), so the guard loses nothing.
Verified against the repro: with the guard the crash is gone. Note that nitro's hotUpdate hooks then crash the same way (the root cause is arguably that Vite hands an unwrapped hotUpdate to Rolldown, which affects any plugin using environment-dependent hotUpdate hooks), but the guard is correct for this plugin regardless of where the systemic fix lands.
test:eslint, test:types, and test:unit pass for the affected package. The guard needs an eslint-disable for no-unnecessary-condition because Vite's types declare this.environment as always present; at runtime under bundledDev it is not.
🤖 Generated with Claude Code
Summary by CodeRabbit#
- Bug Fixes
- Improved development-mode stability when using Vite’s bundled development workflow.
- Prevented hot updates from failing when the required development environment is unavailable.
- Ensured development changes continue to be handled safely when environment details are not available.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
08a2e63a-ecef-4e8c-a2a9-0369c8e6f870📥 Commits
Reviewing files that changed from the base of the PR and between 61d61dfa062917b5faf88626b3fa7a6f5c10a46b and d94bd93b2d5e990d3360cfa412852734669cd282.
📒 Files selected for processing (1)
packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthrough
Walkthrough#
The compiler plugin now exits early from
hotUpdatewhen Vite provides no environment. A patch changeset documents the bundled development fix.Changes#
Compiler hot update handling
packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts,.changeset/start-compiler-hot-update-bundled-dev.mdhotUpdatehook returns whenthis.environmentis unavailable. The changeset documents the patch.Estimated code review effort: 2 (Simple) | ~5 minutes
Mergeability Score: ⚪ Minimal · up to
d94bdThis localized change prevents the bundled development hot-update failure, and no actionable merge-blocking risk remains beyond normal checks and review.
Possibly related issues
hotUpdatefailures whenthis.environmentis unavailable under Vite’sexperimental.bundledDevmode.🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
hotUpdatehook whenthis.environmentis missing.✨ Finishing Touches
🧪 Generate unit tests (beta)
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.
❤️ Share