tajo / react-titled

📃 Set document.title with ease. Nested. Flexible.
MIT License
47 stars 5 forks source link

Title doesn't update in some situations with react-router #17

Open adibsaad opened 1 year ago

adibsaad commented 1 year ago

Hello, Thank you for making this library. It is much-needed! 😄

I was trying to use this in my app with react-router, but I'm running into a bug where the title doesn't get updated when navigating from a child route to parent route or from a route with a Titled to a route without one.

Code: https://codesandbox.io/p/sandbox/snowy-cloud-x9z7lq Demo: https://x9z7lq-5173.csb.app/

To replicate the first issue:

To replicate the second issue

adibsaad commented 1 year ago

Worth noting: if I make separate components and use them for the route element, the bug still exists https://codesandbox.io/p/sandbox/charming-thunder-jxh8zg

vezaynk commented 1 year ago

I can confirm this is happening. I tried downgrading to version 1.1.1 -- same issue. Really strange. I remember testing something similar before adopting the library and didn't encounter this.

jasikpark commented 7 months ago

From testing, I believe this is because RRv6 tries to prevent rerenders as much as possible, whereas this library only reconciles document.title on render.

If I add a useLocation hook to my component for example, the title updates correctly.

jasikpark commented 5 days ago

Considering adding some sort of dependence on the location to manage this, I'm not sure what the right answer is...