Skip to content

Commit

Permalink
Fixed bug causing routes not to render on change (#224)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AlexanderKaran authored Feb 29, 2024
1 parent 1b6c3c8 commit a00d5b3
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 185 deletions.
9 changes: 7 additions & 2 deletions examples/basic-routing/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';

import { About } from './about';
import { Home } from './home';
Expand Down Expand Up @@ -42,4 +42,9 @@ const App = () => {
);
};

render(<App />, document.getElementById('root'));
const container = document.getElementById('root');
if (!container)
throw new Error('No root element found to render basic routing example');

const root = createRoot(container);
root.render(<App />);
9 changes: 7 additions & 2 deletions examples/hash-routing/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHashHistory as createHashHistory4 } from 'history';
import { createHashHistory as createHashHistory5 } from 'history-5';
import React from 'react';
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';

import { About } from './about';
import { Home } from './home';
Expand Down Expand Up @@ -42,4 +42,9 @@ const App = () => {
);
};

render(<App />, document.getElementById('root'));
const container = document.getElementById('root');
if (!container)
throw new Error('No root element found to render hash routing example');

const root = createRoot(container);
root.render(<App />);
9 changes: 7 additions & 2 deletions examples/hooks/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';

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

Expand Down Expand Up @@ -68,4 +68,9 @@ const App = () => {
);
};

render(<App />, document.getElementById('root'));
const container = document.getElementById('root');
if (!container)
throw new Error('No root element found to render hooks example');

const root = createRoot(container);
root.render(<App />);
9 changes: 7 additions & 2 deletions examples/hydration/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMemoryHistory } from 'history';
import React from 'react';
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';
import { defaultRegistry } from 'react-sweet-state';

import { homeRoute } from './routes';
Expand Down Expand Up @@ -53,7 +53,12 @@ const main = async () => {
);
};

render(<App />, document.getElementById('root'));
const container = document.getElementById('root');
if (!container)
throw new Error('No root element found to render hydration example');

const root = createRoot(container);
root.render(<App />);
};

main();
9 changes: 7 additions & 2 deletions examples/routing-with-resources/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from 'react-dom';
import { createRoot } from 'react-dom/client';

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

Expand Down Expand Up @@ -28,4 +28,9 @@ const App = () => {
);
};

render(<App />, document.getElementById('root'));
const container = document.getElementById('root');
if (!container)
throw new Error('No root element found to render resources example');

const root = createRoot(container);
root.render(<App />);
Loading

0 comments on commit a00d5b3

Please sign in to comment.