Skip to content

Commit

Permalink
fix(state): skip one frame on history events to make thinks work when…
Browse files Browse the repository at this point in the history
… routes change
  • Loading branch information
BowlingX committed Dec 5, 2019
1 parent 5692db6 commit 879d10e
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/lib/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,25 @@ export const converter = (historyInstance: History) => (set, get) => {
}
const nextQueries = parse(location.search)
const namespaces = get().namespaces
Object.keys(namespaces).forEach(ns => {
set(
state => {
state.query = applyFlatConfigToState(
state.mappedConfig,
nextQueries,
ns,
state.values,
state.initialValues
)
},
HistoryEventType.REGISTER,
ns
)
// We skip one frame here in case we do route changes
// Because we rely on the state listener in store, it does not fire if it's not initialized
// TODO: Maybe find a better solution, but everything I tried yielded to double rendering of the component
requestAnimationFrame(() => {
Object.keys(namespaces).forEach(ns => {
set(
state => {
state.query = applyFlatConfigToState(
state.mappedConfig,
nextQueries,
ns,
state.values,
state.initialValues
)
},
HistoryEventType.REGISTER,
ns
)
})
})
})

Expand Down

0 comments on commit 879d10e

Please sign in to comment.