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

perf(vite): fix LiveReload proxy bailout logic #7883

Merged
merged 3 commits into from
Nov 3, 2023
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/nervous-fans-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Improve performance of LiveReload proxy in Vite dev
36 changes: 23 additions & 13 deletions integration/vite-css-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ test.describe("Vite CSS dev", () => {
port: ${devPort},
strictPort: true,
},
optimizeDeps: {
include: ["react", "react-dom/client", "@remix-run/react"],
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 need this array defined so that we don't have multiple copies of these dependencies due to our project structure.

},
plugins: [remix()],
});
`,
Expand All @@ -60,28 +63,28 @@ test.describe("Vite CSS dev", () => {
);
}
`,
"app/routes/_index/styles-bundled.css": css`
"app/styles-bundled.css": css`
.index_bundled {
background: papayawhip;
padding: ${TEST_PADDING_VALUE};
}
`,
"app/routes/_index/styles-linked.css": css`
"app/styles-linked.css": css`
.index_linked {
background: salmon;
padding: ${TEST_PADDING_VALUE};
}
`,
"app/routes/_index/styles.module.css": css`
"app/styles.module.css": css`
.index {
background: peachpuff;
padding: ${TEST_PADDING_VALUE};
}
`,
"app/routes/_index/route.tsx": js`
import "./styles-bundled.css";
import linkedStyles from "./styles-linked.css?url";
import cssModulesStyles from "./styles.module.css";
"app/routes/_index.tsx": js`
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 is fixing an unrelated issue with the test while I'm here. The template already contains app/routes/_index.tsx, so we were adding a conflicting route with app/routes/_index/route.tsx.

import "../styles-bundled.css";
import linkedStyles from "../styles-linked.css?url";
import cssModulesStyles from "../styles.module.css";

export function links() {
return [{ rel: "stylesheet", href: linkedStyles }];
Expand Down Expand Up @@ -160,9 +163,16 @@ test.describe("Vite CSS dev", () => {
test.describe("with JS", () => {
test.use({ javaScriptEnabled: true });
test("updates CSS", async ({ page }) => {
let pageErrors: unknown[] = [];
page.on("pageerror", (error) => pageErrors.push(error));

await page.goto(`http://localhost:${devPort}/`, {
waitUntil: "networkidle",
});

// Ensure no errors on page load
expect(pageErrors).toEqual([]);

await expect(page.locator("#index [data-css-modules]")).toHaveCSS(
"padding",
TEST_PADDING_VALUE
Expand All @@ -177,11 +187,11 @@ test.describe("Vite CSS dev", () => {
);

let bundledCssContents = await fs.readFile(
path.join(projectDir, "app/routes/_index/styles-bundled.css"),
path.join(projectDir, "app/styles-bundled.css"),
"utf8"
);
await fs.writeFile(
path.join(projectDir, "app/routes/_index/styles-bundled.css"),
path.join(projectDir, "app/styles-bundled.css"),
bundledCssContents.replace(
TEST_PADDING_VALUE,
UPDATED_TEST_PADDING_VALUE
Expand All @@ -190,11 +200,11 @@ test.describe("Vite CSS dev", () => {
);

let linkedCssContents = await fs.readFile(
path.join(projectDir, "app/routes/_index/styles-linked.css"),
path.join(projectDir, "app/styles-linked.css"),
"utf8"
);
await fs.writeFile(
path.join(projectDir, "app/routes/_index/styles-linked.css"),
path.join(projectDir, "app/styles-linked.css"),
linkedCssContents.replace(
TEST_PADDING_VALUE,
UPDATED_TEST_PADDING_VALUE
Expand All @@ -203,11 +213,11 @@ test.describe("Vite CSS dev", () => {
);

let cssModuleContents = await fs.readFile(
path.join(projectDir, "app/routes/_index/styles.module.css"),
path.join(projectDir, "app/styles.module.css"),
"utf8"
);
await fs.writeFile(
path.join(projectDir, "app/routes/_index/styles.module.css"),
path.join(projectDir, "app/styles.module.css"),
cssModuleContents.replace(
TEST_PADDING_VALUE,
UPDATED_TEST_PADDING_VALUE
Expand Down
4 changes: 2 additions & 2 deletions integration/vite-dev-express-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ test.beforeAll(async () => {
hmr: {
port: ${hmrPort}
}
},
},
optimizeDeps: {
include: ["react", "react-dom/client"],
include: ["react", "react-dom/client", "@remix-run/react"],
},
plugins: [remix()],
});
Expand Down
3 changes: 3 additions & 0 deletions integration/vite-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ test.describe("Vite dev", () => {
port: ${devPort},
strictPort: true,
},
optimizeDeps: {
include: ["react", "react-dom/client", "@remix-run/react"],
},
plugins: [remix()],
});
`,
Expand Down
8 changes: 4 additions & 4 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,11 +666,11 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
return;
}

let hasLiveReloadHints =
code.includes("LiveReload") && code.includes("@remix-run/react");

// Don't transform files that don't need the proxy
if (
!code.includes("@remix-run/react") &&
!code.includes("LiveReload")
) {
if (!hasLiveReloadHints) {
return;
}

Expand Down