Skip to content

Commit d41a2cf

Browse files
committed
update rule for unstable_cache
1 parent dabc72a commit d41a2cf

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
`;
@@ -58,7 +89,7 @@ export const patchFetchCacheForISR: CodePatcher = {
5889
{ escape: false },
5990
),
6091
contentFilter: /\.isOnDemandRevalidate/,
61-
patchCode: createPatchCode(fetchRule),
92+
patchCode: createPatchCode(fetchRule, Lang.JavaScript),
6293
},
6394
},
6495
],
@@ -68,14 +99,14 @@ export const patchUnstableCacheForISR: CodePatcher = {
6899
name: "patch-unstable-cache-for-isr",
69100
patches: [
70101
{
71-
after: "14.0.0",
102+
after: "14.2.0",
72103
field: {
73104
pathFilter: getCrossPlatformPathRegex(
74-
String.raw`(spec-extension/unstable-cache\.js)$`,
105+
String.raw`(server/chunks/.*\.js|.*\.runtime\..*\.js|spec-extension/unstable-cache\.js)$`,
75106
{ escape: false },
76107
),
77108
contentFilter: /\.isOnDemandRevalidate/,
78-
patchCode: createPatchCode(unstable_cacheRule),
109+
patchCode: createPatchCode(unstable_cacheRule, Lang.JavaScript),
79110
},
80111
},
81112
],

0 commit comments

Comments
 (0)