Skip to content

fix(vite): skip full reload for server only modules scanned by client css#19745

Open
hi-ogawa wants to merge 4 commits intotailwindlabs:mainfrom
hi-ogawa:03-02-fix_vite_skip_full_reload_for_server_only_modules_watched_by_client
Open

fix(vite): skip full reload for server only modules scanned by client css#19745
hi-ogawa wants to merge 4 commits intotailwindlabs:mainfrom
hi-ogawa:03-02-fix_vite_skip_full_reload_for_server_only_modules_watched_by_client

Conversation

@hi-ogawa
Copy link

@hi-ogawa hi-ogawa commented Mar 2, 2026

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-rsc CI and confirmed the fix vitejs/vite-plugin-react#1132

@hi-ogawa hi-ogawa marked this pull request as ready for review March 2, 2026 09:46
@hi-ogawa hi-ogawa requested a review from a team as a code owner March 2, 2026 09:46
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

Walkthrough

This 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)
Check name Status Explanation
Title check ✅ Passed The PR title clearly describes the main change: preventing full reloads for server-only modules scanned by client CSS, which aligns with the core fix implemented in the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the regression fix, linked issues, test plan, and validation approach for preventing forced reloads of server-only modules.
Linked Issues check ✅ Passed The PR addresses all three linked issues by implementing an environment-module-graph check that prevents full reloads for server-only modules, restoring HMR/HDR functionality across SSR and client boundaries.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objectives: the Vite plugin fix targets server-only module handling, and the test case specifically validates server HMR behavior for React router HDR scenarios.

✏️ 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).
Share your feedback on Discord.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/@tailwindcss-vite/src/index.ts (1)

222-229: Variable modules shadows the function parameter.

On line 225, const modules shadows the modules parameter 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.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf2e2fe and 93ca94c.

📒 Files selected for processing (2)
  • integrations/vite/react-router.test.ts
  • packages/@tailwindcss-vite/src/index.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant