Skip to content

Commit

Permalink
fix: react 18 Strict mode issues
Browse files Browse the repository at this point in the history
The one behavioral change made is that The Router component will no longer `dispose` of the farce navigation subscription on unmount. This never was correct to do in the first place since remounting would not re subscribe. If you need to tear down the farce protocol you can dispatch dispose manually
  • Loading branch information
jquense committed Aug 31, 2022
1 parent c7d0301 commit 5c82516
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/createBaseRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export default function createBaseRouter({
element: initialRenderArgs ? render(initialRenderArgs) : null,
};

this.mounted = true;

this.lastIteration = 0;
this.pendingResolvedMatch = false;

Expand All @@ -60,6 +58,7 @@ export default function createBaseRouter({
// about having to pass around nextProps.

componentDidMount() {
this.mounted = true;
if (!this.props.initialRenderArgs) {
this.resolveMatch();
}
Expand Down
17 changes: 3 additions & 14 deletions src/createFarceRouter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import useIsomorphicEffect from '@restart/hooks/useIsomorphicEffect';
import FarceActions from 'farce/Actions';
import React, {
forwardRef,
useEffect,
useImperativeHandle,
useState,
} from 'react';
import React, { forwardRef, useImperativeHandle, useState } from 'react';

import createBaseRouter from './createBaseRouter';
import createFarceStore from './createFarceStore';
Expand Down Expand Up @@ -48,17 +42,12 @@ export default function createFarceRouter({
});
}, []);

useEffect(() => {
return () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
store.dispatch(FarceActions.dispose());
};
}, []);

useImperativeHandle(ref, () => store, []);

return <Router {...props} {...state} store={store} />;
});

FarceRouter.displayName = 'FarceRouter';

return FarceRouter;
}

0 comments on commit 5c82516

Please sign in to comment.