Skip to content

Commit a9190de

Browse files
authored
Resolve bugs related to not handling tailStream (#9039)
1 parent 6291fa1 commit a9190de

File tree

15 files changed

+159
-11
lines changed

15 files changed

+159
-11
lines changed

.changeset/tame-views-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/vite-plugin": patch
3+
---
4+
5+
Fixes two bugs that were caused by not accounting for an undocumented method on Workers and Durable Objects. `ctx.blockConcurrencyWhile` will now successfully block execution in Durable Objects and invoking Workers will no longer cause unhandled rejections.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { expect, test } from "vitest";
2+
import { getJsonResponse } from "../../__test-utils__";
3+
4+
test("blocks execution until `ctx.blockConcurrencyWhile` has completed", async () => {
5+
const response = await getJsonResponse("/durable-object");
6+
expect(response).toEqual({ isInitialized: true });
7+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@playground/block-concurrency-while",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "vite build --app",
7+
"check:types": "tsc --build",
8+
"dev": "vite dev",
9+
"preview": "vite preview"
10+
},
11+
"devDependencies": {
12+
"@cloudflare/vite-plugin": "workspace:*",
13+
"@cloudflare/workers-tsconfig": "workspace:*",
14+
"@cloudflare/workers-types": "^4.20250422.0",
15+
"typescript": "catalog:default",
16+
"vite": "catalog:vite-plugin",
17+
"wrangler": "workspace:*"
18+
}
19+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { DurableObject } from "cloudflare:workers";
2+
3+
interface Env {
4+
MyDurableObject: DurableObjectNamespace<MyDurableObject>;
5+
}
6+
7+
export class MyDurableObject extends DurableObject {
8+
#isInitialized = false;
9+
10+
constructor(ctx: DurableObjectState, env: Env) {
11+
super(ctx, env);
12+
console.log("constructor");
13+
this.ctx.blockConcurrencyWhile(async () => {
14+
console.log("blockConcurrencyWhile");
15+
this.#isInitialized = true;
16+
});
17+
}
18+
19+
get isInitialized() {
20+
console.log("isInitialized");
21+
return this.#isInitialized;
22+
}
23+
}
24+
25+
export default {
26+
async fetch(request, env) {
27+
const url = new URL(request.url);
28+
29+
if (url.pathname === "/durable-object") {
30+
const id = env.MyDurableObject.idFromName("test-id");
31+
const stub = env.MyDurableObject.get(id);
32+
33+
return Response.json({ isInitialized: await stub.isInitialized });
34+
}
35+
36+
return new Response(null, { status: 404 });
37+
},
38+
} satisfies ExportedHandler<Env>;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files": [],
3+
"references": [
4+
{ "path": "./tsconfig.node.json" },
5+
{ "path": "./tsconfig.worker.json" }
6+
]
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": ["@cloudflare/workers-tsconfig/base.json"],
3+
"include": ["vite.config.ts", "__tests__"]
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": ["@cloudflare/workers-tsconfig/worker.json"],
3+
"include": ["src"]
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "http://turbo.build/schema.json",
3+
"extends": ["//"],
4+
"tasks": {
5+
"build": {
6+
"outputs": ["dist/**"]
7+
}
8+
}
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { cloudflare } from "@cloudflare/vite-plugin";
2+
import { defineConfig } from "vite";
3+
4+
export default defineConfig({
5+
plugins: [cloudflare({ inspectorPort: false, persistState: false })],
6+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "worker",
3+
"main": "./src/index.ts",
4+
"compatibility_date": "2024-12-30",
5+
"durable_objects": {
6+
"bindings": [
7+
{
8+
"name": "MyDurableObject",
9+
"class_name": "MyDurableObject",
10+
},
11+
],
12+
},
13+
"migrations": [
14+
{
15+
"tag": "v1",
16+
"new_classes": ["MyDurableObject"],
17+
},
18+
],
19+
}

0 commit comments

Comments
 (0)