Fix an issue with react router and dev mode for the /new route. (#4063)

In dev mode you get the below error when visiting the `/new` route. The
route seems to be hit several times before finally navigating to the
correct room. This seems to solve it.


![image](https://github.com/tldraw/tldraw/assets/2523721/cbc4a6ef-9168-414f-b07a-b4d6af6d7256)

### Change type

- [x] `bugfix`
- [ ] `improvement`
- [ ] `feature`
- [ ] `api`
- [ ] `other`


### Release notes

- Fixed a but with navigating to `/new`.
This commit is contained in:
Mitja Bezenšek 2024-07-03 10:39:53 +02:00 committed by GitHub
parent dcfc6da604
commit 51e81d8357
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,6 +24,11 @@ const { loader, useData } = defineLoader(async (_args) => {
export { loader }
// Using this directly in Navigate caused a "Maximum update depth exceeded" error in dev
const state = {
shouldOpenShareMenu: true,
}
export function Component() {
const data = useData()
if (!data)
@ -36,13 +41,5 @@ export function Component() {
/>
)
return (
<Navigate
replace
state={{
shouldOpenShareMenu: true,
}}
to={`/${ROOM_PREFIX}/${data.slug}`}
/>
)
return <Navigate replace state={state} to={`/${ROOM_PREFIX}/${data.slug}`} />
}