Skip to content

Commit a00d5b3

Browse files
Fixed bug causing routes not to render on change (#224)
* Fixed bug causing routes not to render on change * Added unlisten to store cleanup and updated await to give component time to unmount in test
1 parent 1b6c3c8 commit a00d5b3

File tree

9 files changed

+257
-185
lines changed

9 files changed

+257
-185
lines changed

examples/basic-routing/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render } from 'react-dom';
2+
import { createRoot } from 'react-dom/client';
33

44
import { About } from './about';
55
import { Home } from './home';
@@ -42,4 +42,9 @@ const App = () => {
4242
);
4343
};
4444

45-
render(<App />, document.getElementById('root'));
45+
const container = document.getElementById('root');
46+
if (!container)
47+
throw new Error('No root element found to render basic routing example');
48+
49+
const root = createRoot(container);
50+
root.render(<App />);

examples/hash-routing/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createHashHistory as createHashHistory4 } from 'history';
22
import { createHashHistory as createHashHistory5 } from 'history-5';
33
import React from 'react';
4-
import { render } from 'react-dom';
4+
import { createRoot } from 'react-dom/client';
55

66
import { About } from './about';
77
import { Home } from './home';
@@ -42,4 +42,9 @@ const App = () => {
4242
);
4343
};
4444

45-
render(<App />, document.getElementById('root'));
45+
const container = document.getElementById('root');
46+
if (!container)
47+
throw new Error('No root element found to render hash routing example');
48+
49+
const root = createRoot(container);
50+
root.render(<App />);

examples/hooks/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render } from 'react-dom';
2+
import { createRoot } from 'react-dom/client';
33

44
import { shouldReloadWhenRouteMatchChanges } from '../../src/utils';
55

@@ -68,4 +68,9 @@ const App = () => {
6868
);
6969
};
7070

71-
render(<App />, document.getElementById('root'));
71+
const container = document.getElementById('root');
72+
if (!container)
73+
throw new Error('No root element found to render hooks example');
74+
75+
const root = createRoot(container);
76+
root.render(<App />);

examples/hydration/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createMemoryHistory } from 'history';
22
import React from 'react';
3-
import { render } from 'react-dom';
3+
import { createRoot } from 'react-dom/client';
44
import { defaultRegistry } from 'react-sweet-state';
55

66
import { homeRoute } from './routes';
@@ -53,7 +53,12 @@ const main = async () => {
5353
);
5454
};
5555

56-
render(<App />, document.getElementById('root'));
56+
const container = document.getElementById('root');
57+
if (!container)
58+
throw new Error('No root element found to render hydration example');
59+
60+
const root = createRoot(container);
61+
root.render(<App />);
5762
};
5863

5964
main();

examples/routing-with-resources/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render } from 'react-dom';
2+
import { createRoot } from 'react-dom/client';
33

44
import { homeRoute, aboutRoute } from './routes';
55

@@ -28,4 +28,9 @@ const App = () => {
2828
);
2929
};
3030

31-
render(<App />, document.getElementById('root'));
31+
const container = document.getElementById('root');
32+
if (!container)
33+
throw new Error('No root element found to render resources example');
34+
35+
const root = createRoot(container);
36+
root.render(<App />);

0 commit comments

Comments
 (0)