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

Perform HMR updates for non-Astro pages #3651

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 16 additions & 4 deletions packages/astro/src/runtime/client/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,24 @@ if (import.meta.hot) {
}
});
}
function isPage(path: string) {
if (!path.includes('/pages/')) return false;
const parts = path.split('/pages/').slice(1);
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have a config option for pages, so this value will always be correct

let isPrivate = false;
for (const part of parts) {
if (part.startsWith('_')) {
isPrivate = true;
break;
}
}
return !isPrivate;
}
async function updateAll(files: any[]) {
let hasAstroUpdate = false;
let hasPageUpdate = false;
let styles = [];
for (const file of files) {
if (file.acceptedPath.endsWith('.astro')) {
hasAstroUpdate = true;
Comment on lines -41 to -42
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the old "is this a page?" logic, which is incorrect now.

if (isPage(file.acceptedPath)) {
hasPageUpdate = true;
continue;
}
if (file.acceptedPath.includes('svelte&type=style')) {
Expand Down Expand Up @@ -72,7 +84,7 @@ if (import.meta.hot) {
updateStyle(id, content);
}
}
if (hasAstroUpdate) {
if (hasPageUpdate) {
return await updatePage();
}
}
Expand Down