Skip to content

Commit

Permalink
fix: pages and app directory - Uncaught Error: DYNAMIC_SERVER_USAGE (
Browse files Browse the repository at this point in the history
…#4318)

* fix stray DYNAMIC_SERVER_USAGE thrown

* cleanup

* chore: changeset
  • Loading branch information
siddhsuresh authored Apr 2, 2024
1 parent bbe1a54 commit 178c152
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-owls-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"blitz": patch
---

fix: patch next.js to hide intentional throws of `DYNAMIC_SERVER_USAGE`
25 changes: 17 additions & 8 deletions packages/blitz/src/cli/utils/codegen-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ export const codegenTasks = async () => {
*/
const nextDir = await resolveCwd("next")
const nextClientIndex = join(nextDir, "../..", "client", "index.js")
const nextClientOnRecoverableErrorIndex = join(
nextDir,
"../..",
"client",
"on-recoverable-error.js",
)
const readFile = await fs.readFile(nextClientIndex)
const readOnRecoverableErrorFile = await fs.readFile(nextClientOnRecoverableErrorIndex)
const packageJson = await getPackageJson()
const version = packageJson.dependencies.next
const nextVersion = semver.clean(version, {loose: true}) || semver.valid(semver.coerce(version))
Expand Down Expand Up @@ -48,14 +55,16 @@ export const codegenTasks = async () => {
)
await fs.writeFile(nextClientIndex, updatedFile)
log.success("Next.js was successfully patched with a React Suspense fix")
} else if (nextVersion && semver.satisfies(nextVersion, ">=13.3.1")) {
const updatedFile = readFile
.toString()
.replace(
/_onrecoverableerror\.default$/gm,
`(err) => (err.toString().includes("DYNAMIC_SERVER_USAGE") || err.toString().includes("could not finish this Suspense boundary") || err.toString().includes("Minified React error #419")) ? null : _onrecoverableerror.default(err)`,
)
await fs.writeFile(nextClientIndex, updatedFile)
} else {
const updatedFile = readOnRecoverableErrorFile.toString().replace(
/defaultOnRecoverableError\(err\);/gm,
` if (err.toString().includes("DYNAMIC_SERVER_USAGE") || err.toString().includes("could not finish this Suspense boundary") || err.toString().includes("Minified React error #419")) {
return;
} else {
defaultOnRecoverableError(err);
}`,
)
await fs.writeFile(nextClientOnRecoverableErrorIndex, updatedFile)
log.success("Next.js was successfully patched with a React Suspense fix")
}
} catch (err) {
Expand Down

0 comments on commit 178c152

Please sign in to comment.