-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch asyncStorage for ISR and fetch (#503)
* patch asyncStorage for ISR and fetch * Create mighty-elephants-design.md
- Loading branch information
Showing
6 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"open-next": patch | ||
--- | ||
|
||
patch asyncStorage for ISR and fetch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//@ts-nocheck | ||
|
||
const asyncStorage = require("next/dist/client/components/static-generation-async-storage.external.original"); | ||
|
||
const staticGenerationAsyncStorage = { | ||
run: (store, cb, ...args) => | ||
asyncStorage.staticGenerationAsyncStorage.run(store, cb, ...args), | ||
getStore: () => { | ||
const store = asyncStorage.staticGenerationAsyncStorage.getStore(); | ||
if (store) { | ||
store.isOnDemandRevalidate = | ||
store.isOnDemandRevalidate && | ||
!globalThis.__als.getStore().isISRRevalidation; | ||
} | ||
return store; | ||
}, | ||
}; | ||
|
||
exports.staticGenerationAsyncStorage = staticGenerationAsyncStorage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const mod = require("module"); | ||
|
||
const resolveFilename = mod._resolveFilename; | ||
|
||
export function patchAsyncStorage() { | ||
mod._resolveFilename = function ( | ||
originalResolveFilename: typeof resolveFilename, | ||
request: string, | ||
parent: any, | ||
isMain: boolean, | ||
options: any, | ||
) { | ||
if ( | ||
request.endsWith("static-generation-async-storage.external") || | ||
request.endsWith("static-generation-async-storage.external.js") | ||
) { | ||
return require.resolve("./patchedAsyncStorage.cjs"); | ||
} else if ( | ||
request.endsWith("static-generation-async-storage.external.original") | ||
) { | ||
return originalResolveFilename.call( | ||
mod, | ||
request.replace(".original", ".js"), | ||
parent, | ||
isMain, | ||
options, | ||
); | ||
} else | ||
return originalResolveFilename.call( | ||
mod, | ||
request, | ||
parent, | ||
isMain, | ||
options, | ||
); | ||
|
||
// We use `bind` here to avoid referencing outside variables to create potential memory leaks. | ||
}.bind(null, resolveFilename); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters