@tanstack/history
Advanced tools
Comparing version 1.26.10 to 1.28.8
@@ -17,3 +17,3 @@ const pushStateEvent = "pushstate"; | ||
let blockers = []; | ||
const onUpdate = () => { | ||
const notify = () => { | ||
location = opts.getLocation(); | ||
@@ -28,3 +28,3 @@ subscribers.forEach((subscriber) => subscriber()); | ||
if (!allowed) { | ||
(_a = opts.onBlocked) == null ? void 0 : _a.call(opts, onUpdate); | ||
(_a = opts.onBlocked) == null ? void 0 : _a.call(opts, notify); | ||
return; | ||
@@ -50,3 +50,3 @@ } | ||
opts.pushState(path, state); | ||
onUpdate(); | ||
notify(); | ||
}); | ||
@@ -58,3 +58,3 @@ }, | ||
opts.replaceState(path, state); | ||
onUpdate(); | ||
notify(); | ||
}); | ||
@@ -65,3 +65,3 @@ }, | ||
opts.go(index); | ||
onUpdate(); | ||
notify(); | ||
}); | ||
@@ -72,3 +72,3 @@ }, | ||
opts.back(); | ||
onUpdate(); | ||
notify(); | ||
}); | ||
@@ -79,3 +79,3 @@ }, | ||
opts.forward(); | ||
onUpdate(); | ||
notify(); | ||
}); | ||
@@ -106,3 +106,3 @@ }, | ||
}, | ||
notify: onUpdate | ||
notify | ||
}; | ||
@@ -121,2 +121,4 @@ } | ||
const win = (opts == null ? void 0 : opts.window) ?? (typeof document !== "undefined" ? window : void 0); | ||
const originalPushState = win.history.pushState; | ||
const originalReplaceState = win.history.replaceState; | ||
const createHref = (opts == null ? void 0 : opts.createHref) ?? ((path) => path); | ||
@@ -131,22 +133,12 @@ const parseLocation = (opts == null ? void 0 : opts.parseLocation) ?? (() => parseHref( | ||
let next; | ||
let tracking = true; | ||
let scheduled; | ||
const untrack = (fn) => { | ||
tracking = false; | ||
fn(); | ||
tracking = true; | ||
}; | ||
const flush = () => { | ||
untrack(() => { | ||
if (!next) | ||
return; | ||
win.history[next.isPush ? "pushState" : "replaceState"]( | ||
next.state, | ||
"", | ||
next.href | ||
); | ||
next = void 0; | ||
scheduled = void 0; | ||
rollbackLocation = void 0; | ||
}); | ||
if (!next) { | ||
return; | ||
} | ||
const caller = next.isPush ? originalPushState : originalReplaceState; | ||
caller.call(win.history, next.state, "", next.href); | ||
next = void 0; | ||
scheduled = void 0; | ||
rollbackLocation = void 0; | ||
}; | ||
@@ -172,4 +164,2 @@ const queueHistoryAction = (type, destHref, state) => { | ||
}; | ||
const originalPushState = win.history.pushState; | ||
const originalReplaceState = win.history.replaceState; | ||
const history = createHistory({ | ||
@@ -201,4 +191,3 @@ getLocation, | ||
const res = originalPushState.apply(win.history, args); | ||
if (tracking) | ||
history.notify(); | ||
onPushPop(); | ||
return res; | ||
@@ -208,4 +197,3 @@ }; | ||
const res = originalReplaceState.apply(win.history, args); | ||
if (tracking) | ||
history.notify(); | ||
onPushPop(); | ||
return res; | ||
@@ -212,0 +200,0 @@ }; |
{ | ||
"name": "@tanstack/history", | ||
"version": "1.26.10", | ||
"version": "1.28.8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "Tanner Linsley", |
@@ -73,3 +73,3 @@ // While the public API was clearly inspired by the "history" npm package, | ||
const onUpdate = () => { | ||
const notify = () => { | ||
location = opts.getLocation() | ||
@@ -84,3 +84,3 @@ subscribers.forEach((subscriber) => subscriber()) | ||
if (!allowed) { | ||
opts.onBlocked?.(onUpdate) | ||
opts.onBlocked?.(notify) | ||
return | ||
@@ -109,3 +109,3 @@ } | ||
opts.pushState(path, state) | ||
onUpdate() | ||
notify() | ||
}) | ||
@@ -117,3 +117,3 @@ }, | ||
opts.replaceState(path, state) | ||
onUpdate() | ||
notify() | ||
}) | ||
@@ -124,3 +124,3 @@ }, | ||
opts.go(index) | ||
onUpdate() | ||
notify() | ||
}) | ||
@@ -131,3 +131,3 @@ }, | ||
opts.back() | ||
onUpdate() | ||
notify() | ||
}) | ||
@@ -138,3 +138,3 @@ }, | ||
opts.forward() | ||
onUpdate() | ||
notify() | ||
}) | ||
@@ -162,3 +162,3 @@ }, | ||
destroy: () => opts.destroy?.(), | ||
notify: onUpdate, | ||
notify, | ||
} | ||
@@ -202,2 +202,5 @@ } | ||
const originalPushState = win.history.pushState | ||
const originalReplaceState = win.history.replaceState | ||
const createHref = opts?.createHref ?? ((path) => path) | ||
@@ -228,8 +231,2 @@ const parseLocation = | ||
// Because we are proactively updating the location | ||
// in memory before actually updating the browser history, | ||
// we need to track when we are doing this so we don't | ||
// notify subscribers twice on the last update. | ||
let tracking = true | ||
// We need to track the current scheduled update to prevent | ||
@@ -239,25 +236,16 @@ // multiple updates from being scheduled at the same time. | ||
// This function is a wrapper to prevent any of the callback's | ||
// side effects from causing a subscriber notification | ||
const untrack = (fn: () => void) => { | ||
tracking = false | ||
fn() | ||
tracking = true | ||
} | ||
// This function flushes the next update to the browser history | ||
const flush = () => { | ||
// Do not notify subscribers about this push/replace call | ||
untrack(() => { | ||
if (!next) return | ||
win.history[next.isPush ? 'pushState' : 'replaceState']( | ||
next.state, | ||
'', | ||
next.href, | ||
) | ||
// Reset the nextIsPush flag and clear the scheduled update | ||
next = undefined | ||
scheduled = undefined | ||
rollbackLocation = undefined | ||
}) | ||
if (!next) { | ||
return | ||
} | ||
// We use the original push/replace calls here to ensure that | ||
// we do not notify subscribers about this push/replace call | ||
const caller = next.isPush ? originalPushState : originalReplaceState | ||
caller.call(win.history, next.state, '', next.href) | ||
// Reset the nextIsPush flag and clear the scheduled update | ||
next = undefined | ||
scheduled = undefined | ||
rollbackLocation = undefined | ||
} | ||
@@ -298,5 +286,2 @@ | ||
const originalPushState = win.history.pushState | ||
const originalReplaceState = win.history.replaceState | ||
const history = createHistory({ | ||
@@ -333,3 +318,3 @@ getLocation, | ||
const res = originalPushState.apply(win.history, args) | ||
if (tracking) history.notify() | ||
onPushPop() | ||
return res | ||
@@ -340,3 +325,3 @@ } | ||
const res = originalReplaceState.apply(win.history, args) | ||
if (tracking) history.notify() | ||
onPushPop() | ||
return res | ||
@@ -343,0 +328,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65989
940