Skip to content

Commit

Permalink
patch next13 for suspense error (#3956)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dillon Raphael authored Nov 8, 2022
1 parent 2a81af7 commit 88caa18
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-mugs-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"blitz": patch
---

Patch next13 for suspense error
29 changes: 21 additions & 8 deletions packages/blitz/src/cli/utils/codegen-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@ export const codegenTasks = async () => {
const nextDir = await resolveCwd("next")
const nextClientIndex = join(nextDir, "../..", "client", "index.js")
const readFile = await fs.readFile(nextClientIndex)
const updatedFile = readFile
.toString()
.replace(
/ReactDOM\.hydrateRoot\(.*?\);/,
`ReactDOM.hydrateRoot(domEl, reactEl, {onRecoverableError: (err) => (err.toString().includes("could not finish this Suspense boundary") || err.toString().includes("Minified React error #419")) ? null : console.error(err)});`,
)
await fs.writeFile(nextClientIndex, updatedFile)
log.success("Next.js was successfully patched with a React Suspense fix")
const packageJson = await getPackageJson()
const nextVersion = packageJson.dependencies.next
if (nextVersion && nextVersion.startsWith("12")) {
const updatedFile = readFile
.toString()
.replace(
/ReactDOM\.hydrateRoot\(.*?\);/,
`ReactDOM.hydrateRoot(domEl, reactEl, {onRecoverableError: (err) => (err.toString().includes("could not finish this Suspense boundary") || err.toString().includes("Minified React error #419")) ? null : console.error(err)});`,
)
await fs.writeFile(nextClientIndex, updatedFile)
log.success("Next.js was successfully patched with a React Suspense fix")
} else if (nextVersion && nextVersion.startsWith("13")) {
const updatedFile = readFile
.toString()
.replace(
/_client.default\.hydrateRoot\(.*?\);/,
`_client.default.hydrateRoot(domEl, reactEl, {onRecoverableError: (err) => (err.toString().includes("could not finish this Suspense boundary") || err.toString().includes("Minified React error #419")) ? null : console.error(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
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

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

0 comments on commit 88caa18

Please sign in to comment.