Skip to content

Commit 9cce92e

Browse files
authored
fix: set ignoreOutdatedRequests for client environment (#15336)
* fix(cloudflare): ignoreOutdatedRequests in client bundle * test(cloudflare): add e2e test for linked package client:only fix * lock
1 parent 4592be5 commit 9cce92e

8 files changed

Lines changed: 103 additions & 7 deletions

File tree

.changeset/khaki-bushes-stop.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astrojs/cloudflare': patch
3+
---
4+
5+
Fixes a dev server issue where framework components from linked packages would fail to load with a 504 error.
6+
7+
This could occur when using `client:only` or other client directives with components from monorepo packages (linked via `file:` or workspace protocol). The first request would trigger Vite's dependency optimizer mid-request, causing concurrent client module requests to fail.

packages/astro/e2e/cloudflare.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ function sharedTests(testRunner, infoLogs = null) {
9595
);
9696
expect(optimizedLog).toBeUndefined();
9797
});
98+
99+
// Test for https://github.com/vitejs/vite/issues/20867
100+
// When using a linked package with client:only, the first page load can trigger
101+
// Vite's dep optimizer mid-request, causing client scripts to fail with 504.
102+
// The fix sets `ignoreOutdatedRequests: true` on the client environment.
103+
testRunner('linked package with client:only hydrates', async ({ page, astro }) => {
104+
await page.goto(astro.resolveUrl('/linked-package'));
105+
const button = page.locator('#counter');
106+
await expect(button).toBeVisible();
107+
await expect(button).toContainText('Count: 0');
108+
await button.click();
109+
await expect(button).toContainText('Count: 1');
110+
});
98111
}
99112
}
100113

packages/astro/e2e/fixtures/cloudflare/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
"@astrojs/mdx": "^4.3.5",
1212
"@astrojs/react": "workspace:*",
1313
"@astrojs/vue": "workspace:*",
14+
"@test/e2e-my-lib": "workspace:*",
1415
"vue": "^3.5.25",
1516
"@vitejs/plugin-vue": "^6.0.2",
1617
"@types/react": "^18.3.24",
1718
"@types/react-dom": "^18.3.7",
1819
"astro": "workspace:*",
20+
"clsx": "^2.1.1",
1921
"react": "^18.3.1",
2022
"react-dom": "^18.3.1",
2123
"sharp": "^0.34.3"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useState } from "react";
2+
import { jsx } from "react/jsx-runtime";
3+
import { clsx } from "clsx";
4+
5+
export default function Counter() {
6+
const [count, setCount] = useState(0);
7+
return jsx("button", {
8+
id: "counter",
9+
className: clsx("btn"),
10+
onClick: () => setCount(c => c + 1),
11+
children: ["Count: ", count]
12+
});
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@test/e2e-my-lib",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"main": "dist/index.js"
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
export const prerender = false;
3+
import Counter from "@test/e2e-my-lib";
4+
---
5+
<html>
6+
<head>
7+
<title>Linked Package Test</title>
8+
</head>
9+
<body>
10+
<h1>Linked Package with client:only</h1>
11+
<p>This page tests that components from linked packages work with client:only</p>
12+
<div id="counter-container">
13+
<Counter client:only="react" />
14+
</div>
15+
</body>
16+
</html>

packages/integrations/cloudflare/src/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,18 @@ export default function createIntegration(args?: Options): AstroIntegration {
216216
],
217217
},
218218
};
219-
} else if (environmentName === 'client') {
220-
return {
221-
optimizeDeps: {
222-
include: ['astro/runtime/client/dev-toolbar/entrypoint.js'],
223-
},
224-
};
225-
}
219+
} else if (environmentName === 'client') {
220+
return {
221+
optimizeDeps: {
222+
include: ['astro/runtime/client/dev-toolbar/entrypoint.js'],
223+
// Workaround for https://github.com/vitejs/vite/issues/20867
224+
// When dependencies are discovered mid-request (e.g. a linked package
225+
// used with client:only), concurrent requests can fail with 504 because
226+
// the dep optimizer's metadata object gets replaced during `await info.processing`.
227+
ignoreOutdatedRequests: true,
228+
},
229+
};
230+
}
226231
},
227232
},
228233
{

pnpm-lock.yaml

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)