-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(remix-dev/vite): use fs watcher to invalidate manifest instead o…
…f request time (#8164) Co-authored-by: Mark Dalgleish <mark.john.dalgleish@gmail.com>
- Loading branch information
1 parent
8c16935
commit 3218847
Showing
3 changed files
with
105 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { test, expect } from "@playwright/test"; | ||
import getPort from "get-port"; | ||
|
||
import { createProject, viteDev, VITE_CONFIG } from "./helpers/vite.js"; | ||
|
||
const files = { | ||
"app/routes/_index.tsx": String.raw` | ||
import { useState, useEffect } from "react"; | ||
import { Link } from "@remix-run/react"; | ||
export default function IndexRoute() { | ||
const [mounted, setMounted] = useState(false); | ||
useEffect(() => { | ||
setMounted(true); | ||
}, []); | ||
return ( | ||
<p data-mounted>Mounted: {mounted ? "yes" : "no"}</p> | ||
); | ||
} | ||
`, | ||
}; | ||
|
||
test.describe(async () => { | ||
let port: number; | ||
let cwd: string; | ||
let stop: () => void; | ||
|
||
test.beforeAll(async () => { | ||
port = await getPort(); | ||
cwd = await createProject({ | ||
"vite.config.js": await VITE_CONFIG({ port }), | ||
...files, | ||
}); | ||
stop = await viteDev({ cwd, port }); | ||
}); | ||
test.afterAll(async () => await stop()); | ||
|
||
test("Vite / dev / route added", async ({ page }) => { | ||
let pageErrors: Error[] = []; | ||
page.on("pageerror", (error) => pageErrors.push(error)); | ||
|
||
// wait for hydration to make sure initial virtual modules are loaded | ||
await page.goto(`http://localhost:${port}/`, { waitUntil: "networkidle" }); | ||
await expect(page.locator("[data-mounted]")).toHaveText("Mounted: yes"); | ||
|
||
// add new route file | ||
await fs.writeFile( | ||
path.join(cwd, "app/routes/new.tsx"), | ||
String.raw` | ||
export default function Route() { | ||
return ( | ||
<div id="new">new route</div> | ||
); | ||
} | ||
`, | ||
"utf-8" | ||
); | ||
|
||
// client is not notified of new route addition (https://github.com/remix-run/remix/issues/7894) | ||
// however server can handle new route | ||
await expect | ||
.poll(async () => { | ||
await page.goto(`http://localhost:${port}/new`); | ||
return page.getByText("new route").isVisible(); | ||
}) | ||
.toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters