Skip to content

Commit 1a6baa2

Browse files
get everything to work with a single rule
1 parent d169c6a commit 1a6baa2

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

packages/cloudflare/src/cli/build/patches/plugins/fetch-cache-wait-until.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("patchFetchCacheSetMissingWaitUntil", () => {
1818
expect(patchCode(code, rule)).toMatchInlineSnapshot(`
1919
"{
2020
let [o4, a2] = (0, d2.cloneResponse)(e3);
21-
return globalThis.__openNextAls.getStore().waitUntil(o4.arrayBuffer().then(async (e4) => {
21+
return globalThis.__openNextAls?.getStore()?.waitUntil?.(o4.arrayBuffer().then(async (e4) => {
2222
var a3;
2323
let i4 = Buffer.from(e4), s3 = { headers: Object.fromEntries(o4.headers.entries()), body: i4.toString("base64"), status: o4.status, url: o4.url };
2424
null == $ || null == (a3 = $.serverComponentsHmrCache) || a3.set(n2, s3), F && await H.set(n2, { kind: c2.CachedRouteKind.FETCH, data: s3, revalidate: t5 }, { fetchCache: true, revalidate: r4, fetchUrl: _, fetchIdx: q, tags: A2 });
@@ -203,7 +203,7 @@ describe("patchFetchCacheSetMissingWaitUntil", () => {
203203
// We are dynamically rendering including dev mode. We want to return
204204
// the response to the caller as soon as possible because it might stream
205205
// over a very long time.
206-
globalThis.__openNextAls.getStore().waitUntil(cloned1
206+
globalThis.__openNextAls?.getStore()?.waitUntil?.(cloned1
207207
.arrayBuffer()
208208
.then(async (arrayBuffer) => {
209209
const bodyBuffer = Buffer.from(arrayBuffer)
@@ -409,7 +409,7 @@ describe("patchFetchCacheSetMissingWaitUntil", () => {
409409
// We are dynamically rendering including dev mode. We want to return
410410
// the response to the caller as soon as possible because it might stream
411411
// over a very long time.
412-
globalThis.__openNextAls.getStore().waitUntil(res
412+
globalThis.__openNextAls?.getStore()?.waitUntil?.(res
413413
.clone()
414414
.arrayBuffer()
415415
.then(async (arrayBuffer) => {

packages/cloudflare/src/cli/build/patches/plugins/fetch-cache-wait-until.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,21 @@ rule:
3333
kind: call_expression
3434
pattern: $PROMISE
3535
all:
36-
- has: { pattern: "$$$_.then($$$_)", stopBy: end }
36+
- has: { pattern: $_.arrayBuffer().then, stopBy: end }
3737
- has: { pattern: "Buffer.from", stopBy: end }
38-
- has: { regex: "CachedRouteKind.FETCH" }
39-
- has: { regex: "finally(.*?)$" }
38+
- any:
39+
- inside:
40+
kind: sequence_expression
41+
inside:
42+
kind: return_statement
43+
- inside:
44+
kind: expression_statement
45+
precedes:
46+
kind: return_statement
47+
any:
48+
- has: { pattern: $_.FETCH, stopBy: end }
49+
- has: { pattern: FETCH, stopBy: end }
4050
4151
fix: |
42-
globalThis.__openNextAls.getStore().waitUntil($PROMISE)
52+
globalThis.__openNextAls?.getStore()?.waitUntil?.($PROMISE)
4353
`;

0 commit comments

Comments
 (0)