From 29b5f0039056ddfa1de0001c9831b2d133be17dc Mon Sep 17 00:00:00 2001 From: Christian Musa Date: Fri, 4 Oct 2019 23:05:01 -0300 Subject: [PATCH] feat: add prop to disable the initial props cache --- packages/client/flow-typed/beforeComponent_vx.x.x.js | 3 ++- packages/client/src/Before.component.jsx | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/client/flow-typed/beforeComponent_vx.x.x.js b/packages/client/flow-typed/beforeComponent_vx.x.x.js index da22154..6ef0c55 100644 --- a/packages/client/flow-typed/beforeComponent_vx.x.x.js +++ b/packages/client/flow-typed/beforeComponent_vx.x.x.js @@ -164,7 +164,8 @@ declare module 'Before.component' { +staticContext?: StaticRouterContext, +data: ?DataType, +routes: Array, - +req: Request + +req: Request, + +disableInitialPropsCache: Boolean |}; declare module.exports: { diff --git a/packages/client/src/Before.component.jsx b/packages/client/src/Before.component.jsx index 27b0591..9703a9f 100644 --- a/packages/client/src/Before.component.jsx +++ b/packages/client/src/Before.component.jsx @@ -146,7 +146,7 @@ const reducer = (state: BeforeState, { location, type }: BeforeAction) => { * @function */ export function Before(props: BeforeComponentWithRouterProps) { - const { data, routes, location, req, history } = props; + const { data, routes, location, req, history, disableInitialPropsCache } = props; const [state, dispatch] = useReducer(reducer, { currentLocation: location }); @@ -192,7 +192,7 @@ export function Before(props: BeforeComponentWithRouterProps) { useEffect(() => { const unlisten = history.listen((location, action) => { interrupt.current = action === 'POP'; - if (!initialProps.current[location.pathname]) { + if (disableInitialPropsCache || !initialProps.current[location.pathname]) { // This solves a weird case when, on an advanced step of the flow, the user does a browser back const route = getRouteByPathname(location.pathname, routes); if (route) {