Skip to content

Commit

Permalink
Adjust codegen logic for suspense patch (#4138)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Bayer <[email protected]>
Co-authored-by: Siddharth Suresh <[email protected]>
  • Loading branch information
3 people committed May 1, 2023
1 parent 08fbede commit 3d004dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-crews-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/next": minor
---

Fix the DYNAMIC_SERVER_USAGE error for Next.js 13.3.1+
14 changes: 12 additions & 2 deletions packages/blitz/src/cli/utils/codegen-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const codegenTasks = async () => {
*/
const nextDir = await resolveCwd("next")
const nextClientIndex = join(nextDir, "../..", "client", "index.js")
console.log(nextClientIndex)
const readFile = await fs.readFile(nextClientIndex)
const packageJson = await getPackageJson()
const version = packageJson.dependencies.next
Expand All @@ -39,15 +40,24 @@ 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.2")) {
} else if (nextVersion && semver.satisfies(nextVersion, "13.1 - 13.3.0")) {
const updatedFile = readFile
.toString()
.replace(
/_onRecoverableError\.default/,
/_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)
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)
log.success("Next.js was successfully patched with a React Suspense fix")
}
} catch (err) {
log.error(JSON.stringify(err, null, 2))
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit 3d004dc

@deepak-pradhan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed yet

Please sign in to comment.