fix(react-server): fix ?import
query dual package when client module is used at both boundary and non-boundary
#315
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.
The external deps was handled by the virtual module wrapper:
but internal client code still becomes dual package since the one imported at client boundary (e.g.
GlobalProgress
imported by server componentHeader
) will have<id>?import
due toimport(/* @vite-ignore */ id)
, but the one imported not at the boundary (e.g.GlobalProgress
imported by client componentCounter
) will be simply<id>
since it'll go through normal import analysis transform.To avoid this, we can simply expose
import
wrapper as inline script so it won't go through Vite transform.(see also hi-ogawa/vite-environment-examples#69)
Hmm, this scenario still makes dual package after HMR since client component will imports the one with
<id>?t=...
but server component has reference with<id>
. But I guess that's a separate problem already existed before. For now, I added this issue to TODO list #174todo