Closed juliuslipp closed 10 months ago
Hi, thanks for the issue!
The Partial Prerendering feature is marked as highly experimental:
Warning: Partial Prerendering is an experimental feature and is currently not suitable for production environments.
It also has these gotchas:
Partial Prerendering does not yet apply to client-side navigations. We are actively working on this.
There's a good chance that things are not working because something isn't implemented/right yet in Next.js itself. It's also possible that we'll need to update something on our end. Until this feature is in beta or soon to be released we'll however not spend time on this as things aren't settled just yet.
I'd encourage you to open an issue on Next.js and see what the root cause of the error might be. Thanks!
Hey @LekoArts,
Thanks for looking into this. While I see, that this feature is still experimental, I don't agree with your statement that this lies on nexts side.
React throws an error when server features are used (headers, cookies) that is used to determine if a component needs to opt out of static rendering (and will be partially prerendered). Since your implementation uses headers() within a try-catch blog:
Prerendering /_not-found needs to partially bail out because something dynamic was used. React throws a special object to indicate where we need to bail out but it was caught by a try/catch or a Promise was not awaited. These special objects should not be caught by your own try/catch. Learn more: https://nextjs.org/docs/messages/ppr-caught-error
⚠ The following error was thrown during build, and may help identify the source of the issue:
⨯ Error: Clerk: auth() and currentUser() are only supported in App Router (/app directory).
If you're using /pages, try getAuth() instead.
Original error: Error: This page needs to bail out of prerendering at this point because it used headers. React throws this special object to indicate where. It should not be caught by your own try/catch. Learn more: https://nextjs.org/docs/messages/ppr-caught-error
I see that this feature is still experimental, but I am certain it will make it to prod. and also certain that the implementation will be similar to what it is right now, since they don't want to introduce new apis for this.
Here is the matching lines of code: https://github.com/clerk/javascript/blob/main/packages/nextjs/src/app-router/server/utils.ts#L4C1-L21C3
A simple solution would be to determine and integrate the new error message into the rethrow block of buildRequestLike and simply rethrow this error as well.
It is indeed annoying, since I would love to use PPR right now and clerk is the only thing holding me back.
Should be a simple fix. Please reopen. Happy to help :)
Okay, if you think that change alone would make it work, then please put up a PR. As I said we have other priorities right now but happy to look at a PR.
You can (quickly) test this yourself locally:
.next
foldernode_modules/@clerk/nextjs/dist/esm/server/utils.js
and make your change therehey @LekoArts,
Just created a PR. Tested it and fixes the issue :) #2518
Do you roughly know when I can expect it to work with the npm package?
Preliminary Checks
Reproduction / Replay Link
https://github.com/juliuslipp/clerk
Publishable key
pk_test_ZmlybS1waWdsZXQtNjQuY2xlcmsuYWNjb3VudHMuZGV2JA
Description
Steps to reproduce:
see error
remove clerk provider and uncomment headers/cookies in app/recoomended-products.ts
bun run build
see no error
Expected behavior: no error
Actual behavior: error
Environment