11import { getCrossPlatformPathRegex } from "utils/regex.js" ;
22import { createPatchCode } from "./astCodePatcher.js" ;
33import type { CodePatcher } from "./codePatcher" ;
4+ import { Lang } from "@ast-grep/napi" ;
45
56export const fetchRule = `
67rule:
@@ -43,6 +44,36 @@ export const unstable_cacheRule = `
4344rule:
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
4677fix:
4778 ($STORE_OR_CACHE.isOnDemandRevalidate && !globalThis.__openNextAls?.getStore()?.isISRRevalidation)
4879` ;
@@ -58,7 +89,7 @@ export const patchFetchCacheForISR: CodePatcher = {
5889 { escape : false } ,
5990 ) ,
6091 contentFilter : / \. i s O n D e m a n d R e v a l i d a t e / ,
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 : / \. i s O n D e m a n d R e v a l i d a t e / ,
78- patchCode : createPatchCode ( unstable_cacheRule ) ,
109+ patchCode : createPatchCode ( unstable_cacheRule , Lang . JavaScript ) ,
79110 } ,
80111 } ,
81112 ] ,
0 commit comments