Skip to content

Commit

Permalink
chore(wrangler): bump to ^3.93.0
Browse files Browse the repository at this point in the history
wrangler 3.93.0 has an updated unenv using the native workerd stream implementation.
It fixes an issue with server actions.

Ref:
- #147
- unjs/unenv#363
  • Loading branch information
vicb committed Dec 6, 2024
1 parent 5049471 commit 6a75e59
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions examples/middleware/app/stream/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { headers } from "next/headers";
import { NextRequest } from "next/server";

type Item = {
key: string;
value: string;
};

async function* fetchItems(): AsyncGenerator<Item, void, unknown> {
const sleep = async (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

for (let i = 0; i < 10; ++i) {
await sleep(1000);
yield {
key: `key ${i}`,
value: `value ${i}`,
};
}
}

export async function GET(request: NextRequest) {
const stream = new ReadableStream({
async start(controller) {
try {
for await (const item of fetchItems()) {
const data = `data-stream: ${JSON.stringify(item)}\n\n`;
controller.enqueue(new TextEncoder().encode(data));
}
controller.close();
} catch (error) {
controller.error(error);
}
},
});

return new Response(stream, {
headers: {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
Connection: "keep-alive",
"content-encoding": "identity",
},
});
}
2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ catalog:
"tsx": ^4.19.2
"typescript-eslint": ^8.7.0
"vitest": ^2.1.1
"wrangler": ^3.91.0
"wrangler": ^3.93.0

0 comments on commit 6a75e59

Please sign in to comment.