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` ;
@@ -59,20 +90,20 @@ export const patchFetchCacheForISR: CodePatcher = {
5990 } ,
6091 ] ,
6192 contentFilter : / \. i s O n D e m a n d R e v a l i d a t e / ,
62- patchCode : createPatchCode ( fetchRule ) ,
93+ patchCode : createPatchCode ( fetchRule , Lang . JavaScript ) ,
6394} ;
6495
6596export 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 : / \. i s O n D e m a n d R e v a l i d a t e / ,
77- patchCode : createPatchCode ( unstable_cacheRule ) ,
108+ patchCode : createPatchCode ( unstable_cacheRule , Lang . JavaScript ) ,
78109} ;
0 commit comments