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

RichText component throws NextRouter was not mounted #1979

Open
ahiyalala opened this issue Nov 22, 2024 · 2 comments
Open

RichText component throws NextRouter was not mounted #1979

ahiyalala opened this issue Nov 22, 2024 · 2 comments
Labels

Comments

@ahiyalala
Copy link

Describe the Bug

After performing the JSS 21.x to 22.1 upgrade, we encountered an error that reads "NextRouter was not mounted" and after reading the logs it is coming from the RichText component in sitecore-jss-nextjs. I've read in the Next.JS documentation that this is happening only if we are using next/router on an app application; we are using pages.

However if this would help, we are also using turborepo for our jss solution.

image

To Reproduce

Perform JSS upgrade from 21.1.6 to 22.1.0 in succession as described in the documentation

Expected Behavior

useRouter from next/router should not have been an issue because the Next.js application is not running on app version of Next.js

Possible Fix

No response

Provide environment information

  • Sitecore Version: XM Cloud
  • JSS Version: 22.1.0
  • Browser Name and version: Edge
  • Operating System and version (desktop or mobile): Windows 11
@ahiyalala
Copy link
Author

ahiyalala commented Nov 22, 2024

For added information, we used it in this manner on our components:

import { RichText as JssRichText } from '@sitecore-jss/sitecore-jss-nextjs';
import { RichTextProps } from '../RichText.types';

export const Default = (props: RichTextProps): JSX.Element => {
  const id = props.params.RenderingIdentifier;

  return (
    <div
      className={`component rich-text py-mobile md:py-desktop ${props.params.styles.trimEnd()}`}
      id={id ? id : undefined}
    >
      <div className="component-content">
           <JssRichText field={props.fields.Text} />
      </div>
    </div>
  );
};

@pzi
Copy link
Contributor

pzi commented Nov 26, 2024

We encountered the same error during our upgrade and found the same thing in our SSG/ISR application using page router. We initially wrapped our use of the RichText component in a NoSsr component to make it only render on the client, not the server. However, as we updated next and jss further, to later versions, we found we didn't need that any more and it was just working as expected.

What version of next are you using? We're on latest next v14 and latest jss v22.

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

No branches or pull requests

2 participants