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

[BUG] ZenStackHooksProvider causes internal server error in Next.js v14.2.10 or newer #1714

Closed
andrictham opened this issue Sep 18, 2024 · 3 comments

Comments

@andrictham
Copy link

andrictham commented Sep 18, 2024

Description and expected behavior

In Next.js 14.2.10, as well as the latest 14.2.12, wrapping the app in ZenStackHooksProvider as exported from "../lib/hooks" causes Next.js to throw an Internal Server Error on every page.

In development, I see a 500 error in the browser console for every page, even though the page itself renders properly.

This could be due to static generation or SSR of the page failing, but not client-side rendering:

image

This is what’s shown on the server console in development

 ⨯ Internal error: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

In addition, the app will refuse to build during compilation of static pages, with the following build error:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

Next.js 14.2.10 is an urgent security patch, so this is critical to fix. See vulnerability here: GHSA-gp8f-8m3g-qvj9

Everything works in Next.js 14.2.8. This is the last known working version. I have not tried 14.2.9, but it’s possible a change in that version broke something.

Screenshots

Environment (please complete the following information):

  • ZenStack version: 2.5.1
  • Prisma version: 5.19.1
  • Database type: SQLite, PostgreSQL (I have experienced this error on both setups)
  • Next.js versions: 14.2.8 (works), 14.2.10 (broken), 14.2.12 (broken)

Additional context
You can find a reproduction of this bug in this repo, which uses Clerk and ZenStack:
https://github.com/andrictham/zenstack-next-500-error

There are 3 branches:

To setup the repo locally, you’ll need add your Clerk creds to your .env.

@andrictham andrictham changed the title [BUG] ZenStackHooksProvider causes internal server error in Next.js v14.2.10 and newer [BUG] ZenStackHooksProvider causes internal server error in Next.js v14.2.10 or newer Sep 18, 2024
@andrictham andrictham changed the title [BUG] ZenStackHooksProvider causes internal server error in Next.js v14.2.10 or newer [BUG] ZenStackHooksProvider causes internal server error in Next.js v14.2.10 or newer Sep 18, 2024
@jiashengguo jiashengguo added this to the v2.5.x milestone Sep 18, 2024
@ymc9
Copy link
Member

ymc9 commented Sep 20, 2024

Thank you for the detailed bug report and a repro @andrictham ! I'll look into it.

@ymc9 ymc9 modified the milestones: v2.5.x, v2.6.x Sep 23, 2024
@ymc9 ymc9 modified the milestones: v2.6.x, v2.7.0 Sep 30, 2024
@ymc9
Copy link
Member

ymc9 commented Oct 11, 2024

Hi @andrictham , thanks for the wait. It turns out the problem is related to the config in next.config.mjs:

serverComponentsExternalPackages: ["@zenstackhq/runtime"],

The config was needed in older ZenStack releases (when runtime wasn't compatible with Next 13+ RSC handling). It's not needed with new versions anymore. Removing it seems to fix the issue, although I don't know why ... it probably breaks one of the many black magics inside nextjs ...

@ymc9 ymc9 removed this from the v2.7.0 milestone Oct 11, 2024
@andrictham
Copy link
Author

@ymc9 Thanks for helping me track down the source of the issue!

I’ve verified that removing that line does indeed fix the issue and I’m now able to upgrade Next now with no problem.

Will close the issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants