-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
45 additions
and
1 deletion.
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,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", | ||
}, | ||
}); | ||
} |
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 |
---|---|---|
|
@@ -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 |