Skip to content

Commit 9fd0a27

Browse files
committed
patch fetch cache waitUntil
1 parent 0ca267a commit 9fd0a27

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

packages/open-next/src/build/createServerBundle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { generateEdgeBundle } from "./edge/createEdgeBundle.js";
1717
import * as buildHelper from "./helper.js";
1818
import { installDependencies } from "./installDeps.js";
1919
import { type CodePatcher, applyCodePatches } from "./patch/codePatcher.js";
20+
import { patchFetchCacheSetMissingWaitUntil } from "./patch/patchFetchCacheWaitUntil.js";
2021

2122
interface CodeCustomization {
2223
// These patches are meant to apply on user and next generated code
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { getCrossPlatformPathRegex } from "utils/regex.js";
2+
import { createPatchCode } from "./astCodePatcher.js";
3+
import type { CodePatcher } from "./codePatcher";
4+
5+
export const rule = `
6+
rule:
7+
kind: call_expression
8+
pattern: $PROMISE
9+
all:
10+
- has: { pattern: $_.arrayBuffer().then, stopBy: end }
11+
- has: { pattern: "Buffer.from", stopBy: end }
12+
- any:
13+
- inside:
14+
kind: sequence_expression
15+
inside:
16+
kind: return_statement
17+
- inside:
18+
kind: expression_statement
19+
precedes:
20+
kind: return_statement
21+
- has: { pattern: $_.FETCH, stopBy: end }
22+
23+
fix: |
24+
globalThis.__openNextAls?.getStore()?.pendingPromiseRunner.add($PROMISE)
25+
`;
26+
27+
export const patchFetchCacheSetMissingWaitUntil: CodePatcher = {
28+
name: "patch-fetch-cache-set-missing-wait-until",
29+
patches: [
30+
{
31+
versions: ">=15.0.0",
32+
field: {
33+
pathFilter: getCrossPlatformPathRegex(
34+
String.raw`(server/chunks/.*\.js|.*\.runtime\..*\.js|patch-fetch\.js)$`,
35+
{ escape: false },
36+
),
37+
contentFilter: /arrayBuffer\(\)\s*\.then/,
38+
patchCode: createPatchCode(rule),
39+
},
40+
},
41+
],
42+
};

0 commit comments

Comments
 (0)