atlassian-labs / react-resource-router

Configuration driven routing solution for React SPAs that manages route matching, data fetching and progressive rendering
https://atlassian-labs.github.io/react-resource-router
Apache License 2.0
198 stars 28 forks source link

Router state persists last value even when router is removed #177

Open kevin-from-atlassian opened 1 year ago

kevin-from-atlassian commented 1 year ago

Codesandbox: https://codesandbox.io/s/react-resource-router-basic-routing-example-forked-x621v9

When the router is present, the query param updates as expected. However, when the router is removed, the query param value persists the latest value (although it does not update when the query param is changed again). I would expect the value to be undefined (or perhaps an error to be thrown) since there is no router present, but it appears that the useQueryParam reads the value from a global state?

I encountered this with some jest tests, where a component utilizing query parameters had two tests. One wrapped, one not wrapped. Modifying the query param within the component from the wrapped test would affect the value of the query param in the test where the component was not wrapped, behavior that I would not have expected.

E.g.

test 1:
    <MemoryRouter><Component /></MemoryRouter>
    perform some action that changes the query parameter

test 2:
    <Component />
    the query parameter value from the useQueryParam hook is persisted from the previous test