fix(remix-dev/vite): import hmr runtime from main script to ensure script ordering #7916
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.
Closes: #7863
I saw that this issue seems to be addressed by #7842, but I still observed
@vitejs/plugin-react can't detect preamble
after reloading repeatedly like 10 or 20 times (see reproduction in #7863 (comment)), so it might be that "async" attribute doesn't necessarily guarantee execution order.I was looking at the code and it seems pre-vite HMR had already some logic to inject extra
import
in<Scripts />
before running client entry, so I was wondering if there is any downside to use this for vite plugin as well:remix/packages/remix-react/components.tsx
Lines 776 to 777 in 06856da
One clear difference is that this would setup HMR regardless of
LiveReload
, but currently if users didn't includeLiveReload
then they will get the same error@vitejs/plugin-react can't detect preamble
anyway, so it seems this won't do any harm at least (though it may not be ideal eventually).Testing Strategy:
Using the local build of this branch in hi-ogawa/test-remix-vite-hmr-runtime#2, I verified the same error doesn't happen on CI anymore (testing 1000 times reload).