refactor(rsc): use addWatchFile
to invalidate server css virtual
#847
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently we have different css wrapper virtual invalidation strategies.
vite-rsc/css?type=ssr&...
is invalidated via multipleaddWatchFile
:vite-plugin-react/packages/plugin-rsc/src/plugin.ts
Lines 2020 to 2023 in 10987e0
vite-rsc/css?type=rsc&...
is invalidated viahotUpdate
:vite-plugin-react/packages/plugin-rsc/src/plugin.ts
Lines 2134 to 2138 in 10987e0
This PR changes
type=rsc
invalidation to align withtype=ssr
.Notes on why single "addWatchFile" isn't enough
I feel like both should just work with one shot
addWatchFile
. Obviously I tried this before and something wasn't working, but let's try it again and see the issues.It looks like the issue is that
addWatchFile
doesn't help chaining invalidation e.g.Here changing
root.tsx
invalidatesvirtual?root.tsx
, but changingother.tsx
doesn't invalidatevirtual?root.tsx
. Could this be becauseaddWatchFile
makes cycles? Could this be a Vite bug?(EDIT: It looks like this is because of "soft invalidation". technically
virtual
is invalidated but it's only "soft invalidation", so it doesn't trigger load/transform again. When changingaddWatchFile
dep, it causes non-soft invalidation and that's why it works when changingroot.tsx
. See https://github.com/hi-ogawa/reproductions/tree/main/vite-addWatchFile-indirect-invalidate)Note that toggling import in
examples/starter
is working because it togglesimport.meta.viteRsc.loadCss
transform ofroot.tsx
. It would still fail if there were multiple css imports and toggling them individually.vite-plugin-react/packages/plugin-rsc/examples/starter/src/root.tsx
Line 1 in 10987e0