Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust codegen logic for suspense patch #4138

Merged
merged 4 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.