-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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(remix-dev/vite): invalidate route manifest on route export change #8157
Merged
markdalgleish
merged 35 commits into
remix-run:dev
from
hi-ogawa:fix-vite-invalidate-vmod-on-hot-exports-change
Jan 4, 2024
Merged
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
500b839
fix(remix-dev/vite): invalidate route manifest on route exports hot u…
hi-ogawa 08f5a34
fix: forgotten hotData.route
hi-ogawa 04ef12b
test: add e2e
hi-ogawa 33371a7
test: tweak test
hi-ogawa f1f7d7e
Merge branch 'dev' into fix-vite-invalidate-vmod-on-hot-exports-change
hi-ogawa 2792429
Merge branch 'dev' into fix-vite-invalidate-vmod-on-hot-exports-change
hi-ogawa 87bcf0e
Merge branch 'dev' into fix-vite-invalidate-vmod-on-hot-exports-change
hi-ogawa 53a68f5
chore: tweak test 2
hi-ogawa 9988c13
test: tweak 3
hi-ogawa da1e9f7
chore: ci debug
hi-ogawa 0f2cde4
chore: ci debug 2
hi-ogawa 5391698
debug 3
hi-ogawa 2a7f6f1
test: robust assertion
hi-ogawa 75950ad
chore: debug
hi-ogawa 37a04c3
Merge branch 'dev' into fix-vite-invalidate-vmod-on-hot-exports-change
hi-ogawa f460a1e
chore: debug
hi-ogawa 081b578
chore: struggle
hi-ogawa 61fa1ed
chore: debug
hi-ogawa 8a2c818
chore: debug
hi-ogawa cd587ad
chore: debug macos/webkit
hi-ogawa 4ee450d
chore: cache?
hi-ogawa cfad5f7
chore: how about invalidateAll
hi-ogawa 845502d
chore: new page so no cache?
hi-ogawa 0361931
chore: revert debug
hi-ogawa 4ab90d1
chore: revert ci
hi-ogawa 2b145bf
chore: revert debug
hi-ogawa 9bf9c1f
chore: revert ci
hi-ogawa 1b5b246
chore: revert more
hi-ogawa 45c591a
Merge branch 'dev' into fix-vite-invalidate-vmod-on-hot-exports-change
hi-ogawa 98c6152
chore: revert debug
hi-ogawa 11ed15a
Merge branch 'dev' into fix-vite-invalidate-vmod-on-hot-exports-change
markdalgleish 48ca5ed
refactor, add clientAction and clientLoader
markdalgleish 7540baf
refactor test to use createEditor util
markdalgleish 49613c9
add changeset
markdalgleish dff9f79
update test
markdalgleish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,94 @@ | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { test } 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 ( | ||
<div id="index"> | ||
<p data-mounted>Mounted: {mounted ? "yes" : "no"}</p> | ||
<p data-hmr>HMR updated: 0</p> | ||
<Link to="/other">/other</Link> | ||
</div> | ||
); | ||
} | ||
`, | ||
"app/routes/other.tsx": String.raw` | ||
import { useLoaderData } from "@remix-run/react"; | ||
|
||
export const loader = () => "hello"; | ||
|
||
export default function Route() { | ||
const loaderData = useLoaderData(); | ||
return ( | ||
<div id="other">loaderData = {JSON.stringify(loaderData)}</div> | ||
); | ||
} | ||
`, | ||
}; | ||
|
||
test.describe(async () => { | ||
let port: number; | ||
let cwd: string; | ||
let stop: () => Promise<void>; | ||
|
||
test.beforeAll(async () => { | ||
port = await getPort(); | ||
cwd = await createProject({ | ||
"vite.config.js": await VITE_CONFIG({ port }), | ||
...files, | ||
}); | ||
stop = await viteDev({ cwd, port, debug: true }); | ||
}); | ||
test.afterAll(async () => await stop()); | ||
|
||
test("Vite / dev / invalidate manifest on route exports change", async ({ | ||
page, | ||
context, | ||
browserName, | ||
}) => { | ||
let pageErrors: Error[] = []; | ||
page.on("pageerror", (error) => pageErrors.push(error)); | ||
let edit = editor(cwd); | ||
|
||
// wait hydration to ensure initial manifest is loaded | ||
await page.goto(`http://localhost:${port}/`); | ||
await page.getByText("Mounted: yes").click(); | ||
|
||
// remove loader export in other page should invalidate manifest | ||
await edit("app/routes/other.tsx", (contents) => | ||
contents.replace(/export const loader.*/, "") | ||
); | ||
|
||
// after browser reload, client should be aware of there's no loader | ||
if (browserName === "webkit") { | ||
// force new page instance for webkit. | ||
// otherwise browser doesn't seem to fetch new manifest probably due to caching. | ||
page = await context.newPage(); | ||
} | ||
await page.goto(`http://localhost:${port}/`); | ||
await page.getByText("Mounted: yes").click(); | ||
await page.getByRole("link", { name: "/other" }).click(); | ||
await page.getByText("loaderData = null").click(); | ||
}); | ||
}); | ||
|
||
const editor = | ||
(projectDir: string) => | ||
async (file: string, transform: (contents: string) => string) => { | ||
let filepath = path.join(projectDir, file); | ||
let contents = await fs.readFile(filepath, "utf8"); | ||
await fs.writeFile(filepath, transform(contents), "utf8"); | ||
}; |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a very odd quirk on webkit after the huge amount of debugging (on CI).
It seems webkit is using caching for some assets between multiple
page.goto
,reload
, etc... calls.In this test, I'm almost certain that
/@id/__x00__virtual:browser-manifest
(aka.browserManifestId
) was cached and webkit doesn't fetch new manifest whenpage.goto
after server invalidated the module.I hope this behavior is only playwright integration specific quirk and it doesn't happen on local usage of mac/safari.
I would appreciate if someone can verify this locally.