Skip to content

Commit a31d946

Browse files
committed
update rule for unstable_cache
1 parent e204c1a commit a31d946

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

packages/open-next/src/build/patch/patchFetchCacheISR.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getCrossPlatformPathRegex } from "utils/regex.js";
22
import { createPatchCode } from "./astCodePatcher.js";
33
import type { CodePatcher } from "./codePatcher";
4+
import { Lang } from "@ast-grep/napi";
45

56
export const fetchRule = `
67
rule:
@@ -43,6 +44,36 @@ export const unstable_cacheRule = `
4344
rule:
4445
kind: member_expression
4546
pattern: $STORE_OR_CACHE.isOnDemandRevalidate
47+
inside:
48+
kind: if_statement
49+
stopBy: end
50+
has:
51+
kind: statement_block
52+
has:
53+
kind: variable_declarator
54+
has:
55+
kind: await_expression
56+
has:
57+
kind: call_expression
58+
all:
59+
- has:
60+
kind: member_expression
61+
has:
62+
kind: property_identifier
63+
field: property
64+
regex: get
65+
- has:
66+
kind: arguments
67+
has:
68+
kind: object
69+
has:
70+
kind: pair
71+
all:
72+
- has:
73+
kind: property_identifier
74+
field: key
75+
regex: softTags
76+
stopBy: end
4677
fix:
4778
($STORE_OR_CACHE.isOnDemandRevalidate && !globalThis.__openNextAls?.getStore()?.isISRRevalidation)
4879
`;
@@ -59,20 +90,20 @@ export const patchFetchCacheForISR: CodePatcher = {
5990
},
6091
],
6192
contentFilter: /\.isOnDemandRevalidate/,
62-
patchCode: createPatchCode(fetchRule),
93+
patchCode: createPatchCode(fetchRule, Lang.JavaScript),
6394
};
6495

6596
export const patchUnstableCacheForISR: CodePatcher = {
6697
name: "patch-unstable-cache-for-isr",
6798
pathFilter: [
6899
{
69-
after: "14.0.0",
100+
after: "14.2.0",
70101
field: getCrossPlatformPathRegex(
71-
String.raw`(spec-extension/unstable-cache\.js)$`,
102+
String.raw`(server/chunks/.*\.js|.*\.runtime\..*\.js|spec-extension/unstable-cache\.js)$`,
72103
{ escape: false },
73104
),
74105
},
75106
],
76107
contentFilter: /\.isOnDemandRevalidate/,
77-
patchCode: createPatchCode(unstable_cacheRule),
108+
patchCode: createPatchCode(unstable_cacheRule, Lang.JavaScript),
78109
};

0 commit comments

Comments
 (0)