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(vite): fix behind-by-one-render bug for meta HMR #7829

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/fifty-garlics-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

fix behind-by-one-render bug for meta hmr
markdalgleish marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 7 additions & 1 deletion integration/vite-dev-express-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ test.beforeAll(async () => {
// imports
import { useState, useEffect } from "react";

export const meta = () => [{ title: "HMR updated title: 0"}]
pcattori marked this conversation as resolved.
Show resolved Hide resolved

// loader

export default function IndexRoute() {
Expand Down Expand Up @@ -141,16 +143,20 @@ test("Vite custom server HMR & HDR", async ({ page }) => {

// setup: browser state
let hmrStatus = page.locator("#index [data-hmr]");
await expect(page).toHaveTitle("HMR updated title: 0");
await expect(hmrStatus).toHaveText("HMR updated: 0");
let input = page.locator("#index input");
await expect(input).toBeVisible();
await input.type("stateful");

// route: HMR
await edit("app/routes/_index.tsx", (contents) =>
Copy link
Member

Choose a reason for hiding this comment

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

Just noticed you added an edit util. I was thinking of writing this too. This is super nice.

contents.replace("HMR updated: 0", "HMR updated: 1")
contents
.replace("HMR updated title: 0", "HMR updated title: 1")
.replace("HMR updated: 0", "HMR updated: 1")
);
await page.waitForLoadState("networkidle");
await expect(page).toHaveTitle("HMR updated title: 1");
await expect(hmrStatus).toHaveText("HMR updated: 1");
await expect(input).toHaveValue("stateful");

Expand Down
4 changes: 2 additions & 2 deletions packages/remix-dev/vite/static/refresh-utils.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const enqueueUpdate = debounce(async () => {
if (routeUpdates.size > 0) {
manifest = JSON.parse(JSON.stringify(__remixManifest));

routeUpdates.forEach(async (route) => {
for (let route of routeUpdates.values()) {
manifest.routes[route.id] = route;

let imported = await __hmr_import(route.url + "?t=" + Date.now());
Expand All @@ -32,7 +32,7 @@ const enqueueUpdate = debounce(async () => {
: imported.ErrorBoundary,
};
window.__remixRouteModules[route.id] = routeModule;
});
}

let needsRevalidation = new Set(
Array.from(routeUpdates.values())
Expand Down