Skip to content

Commit

Permalink
fix: memory history update
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Aug 7, 2023
1 parent 21b35f7 commit ce575bb
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/router/src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const stopBlocking = () => {

function createHistory(opts: {
getLocation: () => RouterLocation
listener: (onUpdate: () => void) => () => void
listener: false | ((onUpdate: () => void) => () => void)
pushState: (path: string, state: any) => void
replaceState: (path: string, state: any) => void
go: (n: number) => void
Expand All @@ -72,7 +72,9 @@ function createHistory(opts: {
queue.shift()?.()
}

// onUpdate()
if (!opts.listener) {
onUpdate()
}
}

const queueTask = (task: () => void) => {
Expand All @@ -91,7 +93,10 @@ function createHistory(opts: {
},
listen: (cb: () => void) => {
if (listeners.size === 0) {
unsub = opts.listener(onUpdate)
unsub =
typeof opts.listener === 'function'
? opts.listener(onUpdate)
: () => {}
}
listeners.add(cb)

Expand Down Expand Up @@ -229,9 +234,7 @@ export function createMemoryHistory(

return createHistory({
getLocation,
listener: () => {
return () => {}
},
listener: false,
pushState: (path, state) => {
currentState = {
...state,
Expand Down

0 comments on commit ce575bb

Please sign in to comment.