Skip to content

Commit 1383371

Browse files
ostapchmolefrog
authored andcommitted
Extend test cases for the router value memoization
1 parent 755c032 commit 1383371

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/wouter/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export const Router = ({ children, ...props }) => {
180180

181181
next[k] = option;
182182

183-
// the new router is no different from the parent, use parent
183+
// the new router is no different from the parent or from the memoized value, use parent
184184
if (option !== parent[k] || option !== value[k]) value = next;
185185
}
186186

packages/wouter/test/router.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,22 @@ it("updates the context when settings are changed", () => {
243243
expect(state.renders).toEqual(2);
244244
expect(state.base).toEqual("/app");
245245
expect(state.hook).toEqual(newHook);
246+
247+
// should update the context when the base changes as well
248+
rerender(
249+
<Router hook={newHook} base="">
250+
<Memoized />
251+
</Router>
252+
);
253+
expect(state.renders).toEqual(3);
254+
expect(state.base).toEqual("");
255+
expect(state.hook).toEqual(newHook);
256+
257+
// the last check that the router context is stable during re-renders
258+
rerender(
259+
<Router hook={newHook} base="">
260+
<Memoized />
261+
</Router>
262+
);
263+
expect(state.renders).toEqual(3); // nothing changed
246264
});

0 commit comments

Comments
 (0)