-
Notifications
You must be signed in to change notification settings - Fork 277
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
[NextJS] Fix for bug in RichText component - links not reinitialised when content changes #1503
[NextJS] Fix for bug in RichText component - links not reinitialised when content changes #1503
Conversation
Subsequent pages don't have client side routing Added a useEffect dependancy to the NextJs RichText component. This fixes an issue where where the useEffect() hook doesn't run when navigating to a page that contains a RichText component after clicking an internal link in a RichText component on another page to cause the navigation. Description: 1. Open a page that contains a RichText component that has an <a> tag that links to a page within the same site (i.e. clicking the link fires the routeHandler() function within the richText component that performs a client side navigation) 2. When the RichText component on the new page renders, it doesn't run the useEffect hook so the event handler doesn't get attached to any internal links within the RichText component 3. Clicking on any of the embedded links causes a whole page refresh as the event handler isn't attached, so no client side routing occurs.
… the embedded links.
Hi @pschofield ! Thanks for the report, and big thanks for the PR. I've added this to our backlog, we'll triage and see what to do with this next. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pschofield This looks good.
Can I ask you to add a Changelog entry, and then we'll merge it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you so much!
Description / Motivation
When the RichText component content changes, the useEffect() hook is not re-run as it has no dependancies. This means the initializeLinks() function is not run so any embedded internal links within the component will not have the appropriate click event handler. This causes any link within the component to cause a full page load rather than client side routing occuring. This change adds the "hasText" property (essentially the rich text) as a dependancy for the useEffect() hook, ensuring the initializeLinks() function is run when the content changes, enabling client side routing to occur.
Testing Details
Unit test added.
Manual testing involved applying the proposed changes to a local dev instance of Sitecore 10.2 and 10.3 and observing the appropriate event handler is applied to internal links within the rich text component, both on first render but also after the content changes
Types of changes
This PR fixes Bug 1502:
NextJs RichText doesn't allow client side routing when content changes #1502