generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Maintain location.state in React Router frameworks (#840)
* test: Add failing test for issue 839 * fix: Forward user-defined location.state * doc: Add disclaimer about router support
- Loading branch information
Showing
12 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { testRepro839LocationStatePersistence } from 'e2e-shared/specs/react-router/repro-839-location-state-persistence.cy' | ||
|
||
testRepro839LocationStatePersistence({ | ||
path: '/repro-839' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Repro839 } from 'e2e-shared/specs/react-router/repro-839-location-state-persistence' | ||
import { useLocation, useNavigate } from 'react-router-dom' | ||
|
||
export default function Page() { | ||
return <Repro839 useLocation={useLocation} useNavigate={useNavigate} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Repro839 } from 'e2e-shared/specs/react-router/repro-839-location-state-persistence' | ||
import { useLocation, useNavigate } from 'react-router' | ||
|
||
export default function Page() { | ||
return <Repro839 useLocation={useLocation} useNavigate={useNavigate} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { testRepro839LocationStatePersistence } from 'e2e-shared/specs/react-router/repro-839-location-state-persistence.cy' | ||
|
||
testRepro839LocationStatePersistence({ | ||
path: '/repro-839' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useLocation, useNavigate } from '@remix-run/react' | ||
import { Repro839 } from 'e2e-shared/specs/react-router/repro-839-location-state-persistence' | ||
|
||
export default function Page() { | ||
return <Repro839 useLocation={useLocation} useNavigate={useNavigate} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { testRepro839LocationStatePersistence } from 'e2e-shared/specs/react-router/repro-839-location-state-persistence.cy' | ||
|
||
testRepro839LocationStatePersistence({ | ||
path: '/repro-839' | ||
}) |
22 changes: 22 additions & 0 deletions
22
packages/e2e/shared/specs/react-router/repro-839-location-state-persistence.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { createTest } from '../../create-test' | ||
|
||
export const testRepro839LocationStatePersistence = createTest( | ||
'Repro for issue #839 - Location state persistence', | ||
({ path }) => { | ||
it('persists location.state on shallow URL updates', () => { | ||
cy.visit(path) | ||
cy.contains('#hydration-marker', 'hydrated').should('be.hidden') | ||
cy.get('#setup').click() | ||
cy.get('#shallow').click() | ||
cy.get('#state').should('have.text', '{"test":"pass"}') | ||
}) | ||
|
||
it('persists location.state on deep URL updates', () => { | ||
cy.visit(path) | ||
cy.contains('#hydration-marker', 'hydrated').should('be.hidden') | ||
cy.get('#setup').click() | ||
cy.get('#deep').click() | ||
cy.get('#state').should('have.text', '{"test":"pass"}') | ||
}) | ||
} | ||
) |
34 changes: 34 additions & 0 deletions
34
packages/e2e/shared/specs/react-router/repro-839-location-state-persistence.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useQueryState } from 'nuqs' | ||
|
||
type Repro839Props = { | ||
useNavigate: () => (url: string, options: { state: unknown }) => void | ||
useLocation: () => { state: unknown } | ||
} | ||
|
||
export function Repro839({ useNavigate, useLocation }: Repro839Props) { | ||
const navigate = useNavigate() | ||
const location = useLocation() | ||
const [, setShallow] = useQueryState('shallow', { | ||
shallow: true | ||
}) | ||
const [, setDeep] = useQueryState('deep', { | ||
shallow: false | ||
}) | ||
return ( | ||
<> | ||
<button | ||
id="setup" | ||
onClick={() => navigate('.', { state: { test: 'pass' } })} | ||
> | ||
Setup | ||
</button> | ||
<button id="shallow" onClick={() => setShallow('pass')}> | ||
Test shallow | ||
</button> | ||
<button id="deep" onClick={() => setDeep('pass')}> | ||
Test deep | ||
</button> | ||
<pre id="state">{JSON.stringify(location.state)}</pre> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters