fix(nextjs): Fix runtime error for static pages#7476
Conversation
|
I realized that another, possibly more future proof, solution for this would be to try/catch the headers() call as that would not rely on the undocumented import from |
@baked-dev that sounds more reasonable to me. Feel free to update the PR and then we can merge! I'll also take care of writing an e2e test for this so we don't regress here again. Appreciate the contribution! |
|
@AbhiPrasad I updated the code to use try/catch instead. Thank you for taking care of the tests, I was not quite sure if this change was big enough to require additional tests. |
|
@baked-dev - this will go out with a release next early next week! |
|
Thanks for taking care of this. I had this on my short-term to-do list. You implemented it exactly as I would have done with the try-catch block! |
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint) & (yarn test).We had an issue with this aspect of sentry causing our serverless functions on vercel to error.
The reason is that those pages are statically generated at build-time, where the
headersfunction is never called. However the static page revalidation (according to the revalidate config) resulted in an error since theheaderscall causes the page to turn from a static into a dynamic page during runtime, which is not allowed by nextjs.This solution uses the same method next.js uses internally to find out if a request is static and prevents the call to
headersin those cases.