Skip to content

Commit

Permalink
React Suspense on Next 13 patch fix (#4009)
Browse files Browse the repository at this point in the history
* fix: add regex to support inline and non-inline codebase

- add proper regex test for package version

* chore: add changelog

* chore: update lock file

Co-authored-by: Dillon Raphael <[email protected]>
  • Loading branch information
iagormoraes and Dillon Raphael authored Dec 28, 2022
1 parent 4a6612b commit d5b8faa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-toes-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"blitz": patch
---

add regex to support inline and non-inline codebase and proper next.js package version check
8 changes: 4 additions & 4 deletions packages/blitz/src/cli/utils/codegen-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {runPrisma} from "../../utils/run-prisma"
import resolveFrom from "resolve-from"
export const codegenTasks = async () => {
try {
/*
/*
Updates the user's nextjs file and adds onRecoverableError to the hydrateRoot 3rd parameter object.
We can remove this when https://github.com/vercel/next.js/pull/38207 is merged into next.js
*/
Expand All @@ -18,7 +18,7 @@ export const codegenTasks = async () => {
const readFile = await fs.readFile(nextClientIndex)
const packageJson = await getPackageJson()
const nextVersion = packageJson.dependencies.next
if (nextVersion && nextVersion.startsWith("12")) {
if (nextVersion && /^([~^])?12/.test(nextVersion)) {
const updatedFile = readFile
.toString()
.replace(
Expand All @@ -27,11 +27,11 @@ export const codegenTasks = async () => {
)
await fs.writeFile(nextClientIndex, updatedFile)
log.success("Next.js was successfully patched with a React Suspense fix")
} else if (nextVersion && nextVersion.startsWith("13")) {
} else if (nextVersion && /^([~^])?13/.test(nextVersion)) {
const updatedFile = readFile
.toString()
.replace(
/_client.default\.hydrateRoot\(.*?\);/,
/_client\.default\.hydrateRoot\(.*?\{?[\s\S]*?}?\);/,
`_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)
Expand Down

0 comments on commit d5b8faa

Please sign in to comment.