-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby): trigger location effects in navigation (#27594)
* creating test to detect effect change * creating page for e2e test * changing comparison to run on all route changes
- Loading branch information
1 parent
d372db8
commit 642eeb1
Showing
3 changed files
with
60 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
40 changes: 40 additions & 0 deletions
40
e2e-tests/development-runtime/src/pages/navigation-effects.js
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,40 @@ | ||
import React, { useEffect, useState } from "react" | ||
import { navigate } from "gatsby" | ||
|
||
import Layout from "../components/layout" | ||
|
||
export default function NavigationEffects({ location }) { | ||
const [message, setMessage] = useState("Waiting for effect") | ||
|
||
const searchParam = location.search | ||
const searchHash = location.hash | ||
|
||
useEffect(() => { | ||
setMessage(searchParam) | ||
}, [searchParam]) | ||
|
||
useEffect(() => { | ||
setMessage(searchHash) | ||
}, [searchHash]) | ||
|
||
const handleClick = next => navigate(`${next}`, { replace: true }) | ||
|
||
return ( | ||
<Layout> | ||
<h1 data-testid="effect-message">{message}</h1> | ||
|
||
<button | ||
data-testid="send-search-message" | ||
onClick={() => handleClick("?message=searchParam")} | ||
> | ||
Send Search | ||
</button> | ||
<button | ||
data-testid="send-hash-message" | ||
onClick={() => handleClick("#message-hash")} | ||
> | ||
Send Hash | ||
</button> | ||
</Layout> | ||
) | ||
} |
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