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

SSR pages return 500 error due to context being undefined #1042

Open
ChrisManganaro opened this issue May 27, 2022 · 4 comments
Open

SSR pages return 500 error due to context being undefined #1042

ChrisManganaro opened this issue May 27, 2022 · 4 comments
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work 🐞 bug keep

Comments

@ChrisManganaro
Copy link

ChrisManganaro commented May 27, 2022

Description

With using withSitecoreContext HOC, pages built using SSR return 500 due to context being undefined - in production mode.
In testing this issue, I have only be able to reproduce when running the app in production mode locally

Expected behavior

Pages load normally

Steps To Reproduce

  1. Clone https://github.com/ChrisManganaro/sitecore-nextjs-ssr - this was started with the next sample app
  2. npm i
  3. Config a sitecore host
  4. Run npm run start:production
  5. Load application in a browser

Your Environment

TypeError: Cannot read properties of undefined (reading 'context')
    at Object.children (/sites/nextjss-ssr-test/node_modules/@sitecore-jss/sitecore-jss-react/dist/cjs/enhancers/withSitecoreContext.js:15:220)
@pzi
Copy link
Contributor

pzi commented May 27, 2022

The error happens when trying to set the sitecoreContext to context.context on the wrapped component
https://github.com/Sitecore/jss/blob/dev/packages/sitecore-jss-react/src/enhancers/withSitecoreContext.tsx#L35

We also noticed that this only seemed to be an issue on SSR pages on first load.

At build time, pages using getStaticProps build and work fine. E.g. we build a static 404 page and were able to access localhost:3000/404 just fine and were able to navigate around the site fine as well. However, loading an SSR'd page or refreshing a previously loaded page it would cause context to be undefined despite it being set on the provider just fine.

We also believe #1041 would fix the issue we are seeing, but likely not the underlying bug of the context being undefined.

If #1041 is successful, would it be possible to get a patch release on v19 and v20 please?

@illiakovalenko
Copy link
Contributor

withSitecoreContext related issue I added to the backlog, we will triage that

@illiakovalenko
Copy link
Contributor

about #1041 - hotfix will be released

@ambrauer
Copy link
Contributor

Hi @pzi @ChrisManganaro - We investigated a similar (withSitecoreContext HOC) issue and we narrowed it down to what appears to be a bug introduced in Next.js version 12.1.6. The fix is to downgrade to the previous version (i.e. npm i [email protected]). Can you confirm if this resolves your issue as well?

cc @illiakovalenko @sc-addypathania

@illiakovalenko illiakovalenko added the backlog Issue/PR/discussion is reviewed and added to backlog for the further work label Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work 🐞 bug keep
Projects
None yet
Development

No branches or pull requests

4 participants