Skip to content

Commit 60b4d8f

Browse files
committed
why doesnt this work
1 parent 9993458 commit 60b4d8f

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

src/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export function Router(props) {
133133
if (vnode.props.default) d = cloneElement(vnode, m);
134134
});
135135
cur.current = h(RouteContext.Provider, { value: m }, pr || d);
136+
136137
// Reset previous children - if rendering succeeds synchronously, we shouldn't render the previous children.
137138
const p = prev.current;
138139
prev.current = null;

test/router.test.js

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { jest, describe, it, beforeEach, expect } from '@jest/globals';
22
import { h, render } from 'preact';
3+
import { useState } from 'preact/hooks';
34
import { html } from 'htm/preact';
45
import { LocationProvider, Router, useLocation, Route, useRoute } from '../src/router.js';
56
import lazy, { ErrorBoundary } from '../src/lazy.js';
@@ -55,25 +56,31 @@ describe('Router', () => {
5556
});
5657
});
5758

58-
it.only('should allow updating props in a route', async () => {
59+
it('should allow updating props in a route', async () => {
5960
const Home = jest.fn(() => html`<h1>Home</h1>`);
6061
const stack = [];
61-
let loc;
62-
render(
63-
html`
62+
let loc, set;
63+
64+
const App = () => {
65+
const [test, setTest] = useState('2');
66+
set = setTest;
67+
return html`
6468
<${LocationProvider}>
65-
<${Router}
66-
onRouteChange=${url => {
67-
stack.push(url);
68-
}}
69-
>
70-
<${Home} path="/" test="2" />
71-
<//>
72-
<${() => {
73-
loc = useLocation();
74-
}} />
69+
<${Router}
70+
onRouteChange=${url => {
71+
stack.push(url);
72+
}}
73+
>
74+
<${Home} path="/" test=${test} />
7575
<//>
76-
`,
76+
<${() => {
77+
loc = useLocation();
78+
}} />
79+
<//>
80+
`;
81+
}
82+
render(
83+
html`<${App} />`,
7784
scratch
7885
);
7986

@@ -87,34 +94,17 @@ describe('Router', () => {
8794
});
8895

8996
Home.mockReset();
97+
set('3')
98+
await sleep(1);
9099

91-
render(
92-
html`
93-
<${LocationProvider}>
94-
<${Router}
95-
onRouteChange=${url => {
96-
stack.push(url);
97-
}}
98-
>
99-
<${Home} path="/" test="3" />
100-
<//>
101-
<${() => {
102-
loc = useLocation();
103-
}} />
104-
<//>
105-
`,
106-
scratch
107-
);
108-
109-
console.log(scratch.outerHTML)
110-
expect(scratch).toHaveProperty('textContent', 'Home');
111100
expect(Home).toHaveBeenCalledWith({ path: '/', query: {}, params: {}, rest: '', test: '3' }, expect.anything());
112101
expect(loc).toMatchObject({
113102
url: '/',
114103
path: '/',
115104
query: {},
116105
route: expect.any(Function)
117106
});
107+
expect(scratch).toHaveProperty('textContent', 'Home');
118108
});
119109

120110
it('should switch between synchronous routes', async () => {

0 commit comments

Comments
 (0)