fix(vite): skip full reload for server only modules scanned by client css#19745
Conversation
WalkthroughThis pull request enhances Hot Data Reload (HDR) handling in Vite integrations. A new test is added to integrations/vite/react-router.test.ts to verify that editing server-only loader dependencies triggers HDR instead of a full page reload. The test creates a React Router application with a server-only module that feeds data to a loader and confirms the update mechanism works correctly. Concurrently, the Tailwind CSS Vite plugin's hotUpdate function is modified to add cross-environment checks, ensuring updates are skipped when modules exist in other environments that are not assets, refining which file changes trigger reloads. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/@tailwindcss-vite/src/index.ts (1)
222-229: Variablemodulesshadows the function parameter.On line 225,
const modulesshadows themodulesparameter from line 190. This reduces readability and could lead to bugs during future maintenance. Consider renaming to clarify it refers to modules in a different environment.♻️ Suggested rename to avoid shadowing
for (const environment of Object.values(server.environments)) { if (environment.name === this.environment.name) continue - const modules = environment.moduleGraph.getModulesByFile(file) - if (modules && [...modules].some((m) => m.type !== 'asset')) { + const envModules = environment.moduleGraph.getModulesByFile(file) + if (envModules && [...envModules].some((m) => m.type !== 'asset')) { return } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/`@tailwindcss-vite/src/index.ts around lines 222 - 229, The local const named "modules" inside the loop over server.environments shadows the function parameter "modules"; rename the loop-local variable (e.g., to "envModules" or "otherEnvModules") and update its usage in the condition that calls environment.moduleGraph.getModulesByFile(file) and the subsequent [...modules].some(...) check so that the parameter "modules" is not shadowed and readability is restored.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/`@tailwindcss-vite/src/index.ts:
- Around line 222-229: The local const named "modules" inside the loop over
server.environments shadows the function parameter "modules"; rename the
loop-local variable (e.g., to "envModules" or "otherEnvModules") and update its
usage in the condition that calls environment.moduleGraph.getModulesByFile(file)
and the subsequent [...modules].some(...) check so that the parameter "modules"
is not shadowed and readability is restored.
Summary
The change in #19670 didn't take account for server only modules managed by SSR framework. Forcing full reload for this path breaks server HMR. This PR added a check to determine whether the same modified file has associated modules in a different environment module graph to avoid this.
Test plan
Added an integration test for React router HDR (server loader hmr). This test fails on main.
Also the local build is tested on
@vitejs/plugin-rscCI and confirmed the fix vitejs/vite-plugin-react#1132