Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HMR for files imported into routes #2077

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/popular-bikes-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/mini-oxygen': patch
---

Fix HMR when changing files imported into routes.
37 changes: 19 additions & 18 deletions packages/mini-oxygen/src/vite/worker-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,26 @@ function fetchEntryModule(publicUrl: URL, env: ViteEnv) {
.then((hmrWs) => {
hmrReady = !!hmrWs;
hmrWs?.addEventListener('message', (message) => {
if (onHmrRecieve) {
if (!message.data) return;
const data: HMRPayload = JSON.parse(message.data.toString());

if (!data) return;

if (data.type === 'update') {
// Invalidate cache synchronously without revalidating the
// module to avoid hanging promises in workerd
for (const update of data.updates) {
runtime.moduleCache.invalidateDepTree([update.path]);
}
} else if (data.type !== 'custom') {
// Custom events are only used in browser HMR, so ignore them.
// This type is wrong in ViteRuntime:
(onHmrRecieve(data) as unknown as Promise<unknown>)?.catch(
(error) => console.error('During SSR HMR:', error),
);
if (!message.data) return;
const data: HMRPayload = JSON.parse(message.data.toString());

if (!data) return;

if (data.type === 'update') {
// Invalidate cache synchronously without revalidating the
// module to avoid hanging promises in workerd
for (const update of data.updates) {
runtime.moduleCache.invalidateDepTree([
update.path,
...(update.ssrInvalidates ?? []),
]);
}
} else if (data.type !== 'custom' && onHmrRecieve) {
// Custom events are only used in browser HMR, so ignore them.
// This type is wrong in ViteRuntime:
(onHmrRecieve(data) as unknown as Promise<unknown>)?.catch(
(error) => console.error('During SSR HMR:', error),
);
}
});
})
Expand Down
Loading