-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Remove useSyncExternalStore in favor of useState #10377
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"react-router": patch | ||
"react-router-dom": patch | ||
--- | ||
|
||
Switched from `useSyncExternalStore` to `useState` for internal `@remix-run/router` router state syncing in `<RouterProvider>`. We found some [subtle bugs](https://codesandbox.io/s/use-sync-external-store-loop-9g7b81) where router state updates got propagated _before_ other normal `useState` updates, which could lead to footguns in `useEffect` calls. |
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 |
---|---|---|
|
@@ -828,19 +828,8 @@ describe("special character tests", () => { | |
}); | ||
|
||
describe("browser routers", () => { | ||
let testWindow: Window; | ||
|
||
beforeEach(() => { | ||
// Need to use our own custom DOM in order to get a working history | ||
const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, { | ||
url: "https://remix.run/", | ||
}); | ||
testWindow = dom.window as unknown as Window; | ||
testWindow.history.pushState({}, "", "/"); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reusing the same window instance across these tests was. ... not smart on my part :) |
||
|
||
it("encodes characters in BrowserRouter", () => { | ||
testWindow.history.replaceState(null, "", "/with space"); | ||
let testWindow = getWindow("/with space"); | ||
|
||
let ctx = render( | ||
<BrowserRouter window={testWindow}> | ||
|
@@ -857,7 +846,7 @@ describe("special character tests", () => { | |
}); | ||
|
||
it("encodes characters in BrowserRouter (navigate)", () => { | ||
testWindow.history.replaceState(null, "", "/"); | ||
let testWindow = getWindow("/"); | ||
|
||
function Start() { | ||
let navigate = useNavigate(); | ||
|
@@ -882,7 +871,7 @@ describe("special character tests", () => { | |
}); | ||
|
||
it("encodes characters in createBrowserRouter", () => { | ||
testWindow.history.replaceState(null, "", "/with space"); | ||
let testWindow = getWindow("/with space"); | ||
|
||
let router = createBrowserRouter( | ||
[{ path: "/with space", element: <ShowPath /> }], | ||
|
@@ -897,7 +886,7 @@ describe("special character tests", () => { | |
}); | ||
|
||
it("encodes characters in createBrowserRouter (navigate)", () => { | ||
testWindow.history.replaceState(null, "", "/with space"); | ||
let testWindow = getWindow("/"); | ||
|
||
function Start() { | ||
let navigate = useNavigate(); | ||
|
@@ -923,19 +912,8 @@ describe("special character tests", () => { | |
}); | ||
|
||
describe("hash routers", () => { | ||
let testWindow: Window; | ||
|
||
beforeEach(() => { | ||
// Need to use our own custom DOM in order to get a working history | ||
const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, { | ||
url: "https://remix.run/", | ||
}); | ||
testWindow = dom.window as unknown as Window; | ||
testWindow.history.pushState({}, "", "/"); | ||
}); | ||
|
||
it("encodes characters in HashRouter", () => { | ||
testWindow.history.replaceState(null, "", "/#/with space"); | ||
let testWindow = getWindow("/#/with space"); | ||
|
||
let ctx = render( | ||
<HashRouter window={testWindow}> | ||
|
@@ -953,7 +931,7 @@ describe("special character tests", () => { | |
}); | ||
|
||
it("encodes characters in HashRouter (navigate)", () => { | ||
testWindow.history.replaceState(null, "", "/"); | ||
let testWindow = getWindow("/"); | ||
|
||
function Start() { | ||
let navigate = useNavigate(); | ||
|
@@ -979,7 +957,7 @@ describe("special character tests", () => { | |
}); | ||
|
||
it("encodes characters in createHashRouter", () => { | ||
testWindow.history.replaceState(null, "", "/#/with space"); | ||
let testWindow = getWindow("/#/with space"); | ||
|
||
let router = createHashRouter( | ||
[{ path: "/with space", element: <ShowPath /> }], | ||
|
@@ -995,7 +973,7 @@ describe("special character tests", () => { | |
}); | ||
|
||
it("encodes characters in createHashRouter (navigate)", () => { | ||
testWindow.history.replaceState(null, "", "/"); | ||
let testWindow = getWindow("/"); | ||
|
||
function Start() { | ||
let navigate = useNavigate(); | ||
|
@@ -1022,3 +1000,13 @@ describe("special character tests", () => { | |
}); | ||
}); | ||
}); | ||
|
||
function getWindow(initialPath) { | ||
// Need to use our own custom DOM in order to get a working history | ||
const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`, { | ||
url: "https://remix.run/", | ||
}); | ||
let testWindow = dom.window as unknown as Window; | ||
testWindow.history.pushState({}, "", initialPath); | ||
return testWindow; | ||
} |
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
32 changes: 0 additions & 32 deletions
32
packages/react-router/lib/use-sync-external-store-shim/index.ts
This file was deleted.
Oops, something went wrong.
152 changes: 0 additions & 152 deletions
152
packages/react-router/lib/use-sync-external-store-shim/useSyncExternalStoreShimClient.ts
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
packages/react-router/lib/use-sync-external-store-shim/useSyncExternalStoreShimServer.ts
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a bonus we drop the
use-sync-external-store/shim
and shave a few bytes