@tanstack/history 0.0.1-beta.204 → 0.0.1-beta.206

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,7 +49,6 @@ function createHistory(opts) {
49
49
  while (queue.length) {
50
50
  queue.shift()?.();
51
51
  }
52
- onUpdate();
53
52
  };
54
53
  const queueTask = task => {
55
54
  queue.push(task);
@@ -109,7 +108,7 @@ function createHistory(opts) {
109
108
  },
110
109
  flush: () => opts.flush?.(),
111
110
  destroy: () => opts.destroy?.(),
112
- update: onUpdate
111
+ notify: onUpdate
113
112
  };
114
113
  }
115
114
  function assignKey(state) {
@@ -195,7 +194,7 @@ function createBrowserHistory(opts) {
195
194
  };
196
195
  const onPushPop = () => {
197
196
  currentLocation = parseLocation(getHref(), window.history.state);
198
- history.update();
197
+ history.notify();
199
198
  };
200
199
  var originalPushState = window.history.pushState;
201
200
  var originalReplaceState = window.history.replaceState;
@@ -219,12 +218,12 @@ function createBrowserHistory(opts) {
219
218
  window.addEventListener(popStateEvent, onPushPop);
220
219
  window.history.pushState = function () {
221
220
  let res = originalPushState.apply(window.history, arguments);
222
- if (tracking) history.update();
221
+ if (tracking) history.notify();
223
222
  return res;
224
223
  };
225
224
  window.history.replaceState = function () {
226
225
  let res = originalReplaceState.apply(window.history, arguments);
227
- if (tracking) history.update();
226
+ if (tracking) history.notify();
228
227
  return res;
229
228
  };
230
229
  return history;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n update: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n\n onUpdate()\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n update: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.update()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.update()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.update()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","update","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;;AAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAMC,YAAY,GAAGA,MAAM;AACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;AAC3DM,IAAAA,OAAO,EAAE,IAAA;AACX,GAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAASC,aAAaA,CAACC,IAUtB,EAAiB;AAChB,EAAA,IAAIC,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;AACjC,EAAA,IAAIC,WAAW,GAAG,IAAIC,GAAG,EAAc,CAAA;EACvC,IAAIC,QAAqB,GAAG,EAAE,CAAA;EAC9B,IAAIC,KAAqB,GAAG,EAAE,CAAA;EAE9B,MAAMC,QAAQ,GAAGA,MAAM;AACrBN,IAAAA,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;IAC7BC,WAAW,CAACK,OAAO,CAAEC,UAAU,IAAKA,UAAU,EAAE,CAAC,CAAA;GAClD,CAAA;EAED,MAAMC,UAAU,GAAGA,MAAM;IACvB,IAAIL,QAAQ,CAACM,MAAM,EAAE;AACnBN,MAAAA,QAAQ,CAAC,CAAC,CAAC,GAAGK,UAAU,EAAE,MAAM;AAC9BL,QAAAA,QAAQ,GAAG,EAAE,CAAA;AACbT,QAAAA,YAAY,EAAE,CAA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K,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;IACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;GAClB,CAAA;AACH,CAAA;;AAEA;AACA,SAASmB,eAAeA,GAAG;AACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;AACtD;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;;AAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAMC,YAAY,GAAGA,MAAM;AACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;AAC3DM,IAAAA,OAAO,EAAE,IAAA;AAC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AAmB,EAAmB;AACzE,EAAA,IAAI0D,SAAS,GAAGvB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;AACjC,EAAA,IAAIC,WAAW,GAAGzB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;EAEnC,OAAO;IACLxB,IAAI;AACJZ,IAAAA,QAAQ,EAAEY,IAAI,CAACe,SAAS,CACtB,CAAC,EACDQ,SAAS,GAAG,CAAC,GACTE,WAAW,GAAG,CAAC,GACbJ,IAAI,CAACC,GAAG,CAACC,SAAS,EAAEE,WAAW,CAAC,GAChCF,SAAS,GACXE,WAAW,GAAG,CAAC,GACfA,WAAW,GACXzB,IAAI,CAAC7C,MACX,CAAC;AACDmC,IAAAA,IAAI,EAAEiC,SAAS,GAAG,CAAC,CAAC,GAAGvB,IAAI,CAACe,SAAS,CAACQ,SAAS,CAAC,GAAG,EAAE;IACrDlC,MAAM,EACJoC,WAAW,GAAG,CAAC,CAAC,GACZzB,IAAI,CAAC0B,KAAK,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;IACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;GAClB,CAAA;AACH,CAAA;;AAEA;AACA,SAASmB,eAAeA,GAAG;AACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;AACtD;;;;;;"}
@@ -45,7 +45,6 @@ function createHistory(opts) {
45
45
  while (queue.length) {
46
46
  queue.shift()?.();
47
47
  }
48
- onUpdate();
49
48
  };
50
49
  const queueTask = task => {
51
50
  queue.push(task);
@@ -105,7 +104,7 @@ function createHistory(opts) {
105
104
  },
106
105
  flush: () => opts.flush?.(),
107
106
  destroy: () => opts.destroy?.(),
108
- update: onUpdate
107
+ notify: onUpdate
109
108
  };
110
109
  }
111
110
  function assignKey(state) {
@@ -191,7 +190,7 @@ function createBrowserHistory(opts) {
191
190
  };
192
191
  const onPushPop = () => {
193
192
  currentLocation = parseLocation(getHref(), window.history.state);
194
- history.update();
193
+ history.notify();
195
194
  };
196
195
  var originalPushState = window.history.pushState;
197
196
  var originalReplaceState = window.history.replaceState;
@@ -215,12 +214,12 @@ function createBrowserHistory(opts) {
215
214
  window.addEventListener(popStateEvent, onPushPop);
216
215
  window.history.pushState = function () {
217
216
  let res = originalPushState.apply(window.history, arguments);
218
- if (tracking) history.update();
217
+ if (tracking) history.notify();
219
218
  return res;
220
219
  };
221
220
  window.history.replaceState = function () {
222
221
  let res = originalReplaceState.apply(window.history, arguments);
223
- if (tracking) history.update();
222
+ if (tracking) history.notify();
224
223
  return res;
225
224
  };
226
225
  return history;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n update: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n\n onUpdate()\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n update: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.update()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.update()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.update()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","update","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;;AAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CA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e,EAAE,EAAGwC,CAAC,IAAKvB,MAAM,CAACM,OAAO,CAACvB,EAAE,CAACwC,CAAC,CAAC;IAC/BpC,UAAU,EAAGV,IAAI,IAAKA,IAAAA;AACxB,GAAC,CAAC,CAAA;AACJ,CAAA;AAEA,SAAS4B,aAAaA,CAACQ,IAAY,EAAEnC,KAAmB,EAAmB;AACzE,EAAA,IAAI0D,SAAS,GAAGvB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;AACjC,EAAA,IAAIC,WAAW,GAAGzB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;EAEnC,OAAO;IACLxB,IAAI;AACJZ,IAAAA,QAAQ,EAAEY,IAAI,CAACe,SAAS,CACtB,CAAC,EACDQ,SAAS,GAAG,CAAC,GACTE,WAAW,GAAG,CAAC,GACbJ,IAAI,CAACC,GAAG,CAACC,SAAS,EAAEE,WAAW,CAAC,GAChCF,SAAS,GACXE,WAAW,GAAG,CAAC,GACfA,WAAW,GACXzB,IAAI,CAAC7C,MACX,CAAC;AACDmC,IAAAA,IAAI,EAAEiC,SAAS,GAAG,CAAC,CAAC,GAAGvB,IAAI,CAACe,SAAS,CAACQ,SAAS,CAAC,GAAG,EAAE;IACrDlC,MAAM,EACJoC,WAAW,GAAG,CAAC,CAAC,GACZzB,IAAI,CAAC0B,KAAK,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;IACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;GAClB,CAAA;AACH,CAAA;;AAEA;AACA,SAASmB,eAAeA,GAAG;AACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;AACtD;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;;AAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAMC,YAAY,GAAGA,MAAM;AACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;AAC3DM,IAAAA,OAAO,EAAE,IAAA;AACX,GAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAASC,aAAaA,CAACC,IAUtB,EAAiB;AAChB,EAAA,IAAIC,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;AACjC,EAAA,IAAIC,WAAW,GAAG,IAAIC,GAAG,EAAc,CAAA;EACvC,IAAIC,QAAqB,GAAG,EAAE,CAAA;EAC9B,IAAIC,KAAqB,GAAG,EAAE,CAAA;EAE9B,MAAMC,QAAQ,GAAGA,MAAM;AACrBN,IAAAA,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;IAC7BC,WAAW,CAACK,OAAO,CAAEC,UAAU,I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ACXzB,IAAI,CAAC7C,MACX,CAAC;AACDmC,IAAAA,IAAI,EAAEiC,SAAS,GAAG,CAAC,CAAC,GAAGvB,IAAI,CAACe,SAAS,CAACQ,SAAS,CAAC,GAAG,EAAE;IACrDlC,MAAM,EACJoC,WAAW,GAAG,CAAC,CAAC,GACZzB,IAAI,CAAC0B,KAAK,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;IACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;GAClB,CAAA;AACH,CAAA;;AAEA;AACA,SAASmB,eAAeA,GAAG;AACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;AACtD;;;;"}
@@ -4024,7 +4024,7 @@ var drawChart = (function (exports) {
4024
4024
  </script>
4025
4025
  <script>
4026
4026
  /*<!--*/
4027
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages/history/src/index.ts","uid":"8e4c-1"}]}],"isRoot":true},"nodeParts":{"8e4c-1":{"renderedLength":8906,"gzipLength":2610,"brotliLength":0,"mainUid":"8e4c-0"}},"nodeMetas":{"8e4c-0":{"id":"/packages/history/src/index.ts","moduleParts":{"index.production.js":"8e4c-1"},"imported":[],"importedBy":[],"isEntry":true}},"env":{"rollup":"2.79.1"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4027
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages/history/src/index.ts","uid":"8d0d-1"}]}],"isRoot":true},"nodeParts":{"8d0d-1":{"renderedLength":8888,"gzipLength":2610,"brotliLength":0,"mainUid":"8d0d-0"}},"nodeMetas":{"8d0d-0":{"id":"/packages/history/src/index.ts","moduleParts":{"index.production.js":"8d0d-1"},"imported":[],"importedBy":[],"isEntry":true}},"env":{"rollup":"2.79.1"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4028
4028
 
4029
4029
  const run = () => {
4030
4030
  const width = window.innerWidth;
@@ -8,7 +8,7 @@
8
8
  "children": [
9
9
  {
10
10
  "name": "packages/history/src/index.ts",
11
- "uid": "8e4c-3"
11
+ "uid": "8d0d-3"
12
12
  }
13
13
  ]
14
14
  }
@@ -16,18 +16,18 @@
16
16
  "isRoot": true
17
17
  },
18
18
  "nodeParts": {
19
- "8e4c-3": {
20
- "renderedLength": 8906,
19
+ "8d0d-3": {
20
+ "renderedLength": 8888,
21
21
  "gzipLength": 2610,
22
22
  "brotliLength": 0,
23
- "mainUid": "8e4c-2"
23
+ "mainUid": "8d0d-2"
24
24
  }
25
25
  },
26
26
  "nodeMetas": {
27
- "8e4c-2": {
27
+ "8d0d-2": {
28
28
  "id": "/packages/history/src/index.ts",
29
29
  "moduleParts": {
30
- "index.production.js": "8e4c-3"
30
+ "index.production.js": "8d0d-3"
31
31
  },
32
32
  "imported": [],
33
33
  "importedBy": [],
@@ -20,7 +20,7 @@ interface RouterHistory {
20
20
  block: (blockerFn: BlockerFn) => () => void;
21
21
  flush: () => void;
22
22
  destroy: () => void;
23
- update: () => void;
23
+ notify: () => void;
24
24
  }
25
25
  interface HistoryLocation extends ParsedPath {
26
26
  state: HistoryState;
@@ -51,7 +51,6 @@
51
51
  while (queue.length) {
52
52
  queue.shift()?.();
53
53
  }
54
- onUpdate();
55
54
  };
56
55
  const queueTask = task => {
57
56
  queue.push(task);
@@ -111,7 +110,7 @@
111
110
  },
112
111
  flush: () => opts.flush?.(),
113
112
  destroy: () => opts.destroy?.(),
114
- update: onUpdate
113
+ notify: onUpdate
115
114
  };
116
115
  }
117
116
  function assignKey(state) {
@@ -197,7 +196,7 @@
197
196
  };
198
197
  const onPushPop = () => {
199
198
  currentLocation = parseLocation(getHref(), window.history.state);
200
- history.update();
199
+ history.notify();
201
200
  };
202
201
  var originalPushState = window.history.pushState;
203
202
  var originalReplaceState = window.history.replaceState;
@@ -221,12 +220,12 @@
221
220
  window.addEventListener(popStateEvent, onPushPop);
222
221
  window.history.pushState = function () {
223
222
  let res = originalPushState.apply(window.history, arguments);
224
- if (tracking) history.update();
223
+ if (tracking) history.notify();
225
224
  return res;
226
225
  };
227
226
  window.history.replaceState = function () {
228
227
  let res = originalReplaceState.apply(window.history, arguments);
229
- if (tracking) history.update();
228
+ if (tracking) history.notify();
230
229
  return res;
231
230
  };
232
231
  return history;
@@ -1 +1 @@
1
- {"version":3,"file":"index.development.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n update: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n\n onUpdate()\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n update: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.update()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.update()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.update()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","update","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;;;;;;;EAAA;EACA;EACA;;EAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;EAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;EAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;EAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;IAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;EACtB;EACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;EAChC,CAAC,CAAA;EAED,MAAMC,YAAY,GAAGA,MAAM;EACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;EAC3DM,IAAAA,OAAO,EAAE,IAAA;EACX,GAAC,CAAC,CAAA;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AY,EAAEnC,KAAmB,EAAmB;EACzE,EAAA,IAAI0D,SAAS,GAAGvB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;EACjC,EAAA,IAAIC,WAAW,GAAGzB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;IAEnC,OAAO;MACLxB,IAAI;EACJZ,IAAAA,QAAQ,EAAEY,IAAI,CAACe,SAAS,CACtB,CAAC,EACDQ,SAAS,GAAG,CAAC,GACTE,WAAW,GAAG,CAAC,GACbJ,IAAI,CAACC,GAAG,CAACC,SAAS,EAAEE,WAAW,CAAC,GAChCF,SAAS,GACXE,WAAW,GAAG,CAAC,GACfA,WAAW,GACXzB,IAAI,CAAC7C,MACX,CAAC;EACDmC,IAAAA,IAAI,EAAEiC,SAAS,GAAG,CAAC,CAAC,GAAGvB,IAAI,CAACe,SAAS,CAACQ,SAAS,CAAC,GAAG,EAAE;MACrDlC,MAAM,EACJoC,WAAW,GAAG,CAAC,CAAC,GACZzB,IAAI,CAAC0B,KAAK,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;MACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;KAClB,CAAA;EACH,CAAA;;EAEA;EACA,SAASmB,eAAeA,GAAG;EACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;EACtD;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.development.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;;;;;;;EAAA;EACA;EACA;;EAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;EAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;EAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;EAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;IAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;EACtB;EACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;EAChC,CAAC,CAAA;EAED,MAAMC,YAAY,GAAGA,MAAM;EACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;EAC3DM,IAAAA,OAAO,EAAE,IAAA;EACX,GAAC,CAAC,CAAA;EACJ,CAAC,CAAA;EAED,SAASC,aAAaA,CAACC,IAUtB,EAAiB;EAChB,EAAA,IAAIC,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;EACjC,EAAA,IAAIC,WAAW,GAAG,IAAIC,GAAG,EAAc,CAAA;IACvC,IAAIC,QAAqB,GAAG,EAAE,CAAA;IAC9B,IAAIC,KAAqB,GAAG,EAAE,CAAA;IAE9B,MAAMC,QAAQ,GAAGA,MAAM;EACrBN,IAAAA,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;MAC7BC,WAAW,CAACK,OAAO,CAAEC,UAAU,IAAKA,UAAU,EAAE,CAAC,CAAA;KAClD,CAAA;IAED,MAAMC,UAAU,GAAGA,MAAM;MACvB,IAAIL,QAAQ,CAACM,MAAM,EAAE;EACnBN,MAAAA,QAAQ,CAAC,CAAC,CAAC,GAAGK,UAAU,EAAE,MA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G,CAAC,CAAC,GACZzB,IAAI,CAAC0B,KAAK,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;MACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;KAClB,CAAA;EACH,CAAA;;EAEA;EACA,SAASmB,eAAeA,GAAG;EACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;EACtD;;;;;;;;;;;;"}
@@ -8,5 +8,5 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TanStackHistory={})}(this,(function(e){"use strict";const t="pushstate",n="popstate",o="beforeunload",r=e=>(e.preventDefault(),e.returnValue=""),i=()=>{removeEventListener(o,r,{capture:!0})};function s(e){let t=e.getLocation(),n=new Set,s=[],h=[];const c=()=>{t=e.getLocation(),n.forEach((e=>e()))},d=()=>{if(s.length)s[0]?.(d,(()=>{s=[],i()}));else{for(;h.length;)h.shift()?.();c()}},u=e=>{h.push(e),d()};return{get location(){return t},subscribe:e=>(n.add(e),()=>{n.delete(e)}),push:(t,n)=>{n=a(n),u((()=>{e.pushState(t,n,c)}))},replace:(t,n)=>{n=a(n),u((()=>{e.replaceState(t,n,c)}))},go:t=>{u((()=>{e.go(t)}))},back:()=>{u((()=>{e.back()}))},forward:()=>{u((()=>{e.forward()}))},createHref:t=>e.createHref(t),block:e=>(s.push(e),1===s.length&&addEventListener(o,r,{capture:!0}),()=>{s=s.filter((t=>t!==e)),s.length||i()}),flush:()=>e.flush?.(),destroy:()=>e.destroy?.(),update:c}}function a(e){return e||(e={}),e.key=d(),e}function h(e){const o=e?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=e?.createHref??(e=>e);let i=c(o(),window.history.state);let a,h,d=!0;const u=()=>{d=!1,(()=>{a&&(window.history[a.isPush?"pushState":"replaceState"](a.state,"",a.href),a=void 0,h=void 0)})(),d=!0},l=(e,t,n,o)=>{const s=r(t);i=c(s,n),a={href:s,state:n,isPush:a?.isPush||"push"===e},o(),h||(h=Promise.resolve().then((()=>u())))},w=()=>{i=c(o(),window.history.state),y.update()};var f=window.history.pushState,p=window.history.replaceState;const y=s({getLocation:()=>i,pushState:(e,t,n)=>l("push",e,t,n),replaceState:(e,t,n)=>l("replace",e,t,n),back:()=>window.history.back(),forward:()=>window.history.forward(),go:e=>window.history.go(e),createHref:e=>r(e),flush:u,destroy:()=>{window.history.pushState=f,window.history.replaceState=p,window.removeEventListener(t,w),window.removeEventListener(n,w)}});return window.addEventListener(t,w),window.addEventListener(n,w),window.history.pushState=function(){let e=f.apply(window.history,arguments);return d&&y.update(),e},window.history.replaceState=function(){let e=p.apply(window.history,arguments);return d&&y.update(),e},y}function c(e,t){let n=e.indexOf("#"),o=e.indexOf("?");return{href:e,pathname:e.substring(0,n>0?o>0?Math.min(n,o):n:o>0?o:e.length),hash:n>-1?e.substring(n):"",search:o>-1?e.slice(o,-1===n?void 0:n):"",state:t||{}}}function d(){return(Math.random()+1).toString(36).substring(7)}e.createBrowserHistory=h,e.createHashHistory=function(){return h({getHref:()=>window.location.hash.substring(1),createHref:e=>`#${e}`})},e.createMemoryHistory=function(e={initialEntries:["/"]}){const t=e.initialEntries;let n=e.initialIndex??t.length-1,o={key:d()};return s({getLocation:()=>c(t[n],o),pushState:(e,r)=>{o=r,t.push(e),n++},replaceState:(e,r)=>{o=r,t[n]=e},back:()=>{n--},forward:()=>{n=Math.min(n+1,t.length-1)},go:e=>window.history.go(e),createHref:e=>e})},Object.defineProperty(e,"__esModule",{value:!0})}));
11
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TanStackHistory={})}(this,(function(e){"use strict";const t="pushstate",n="popstate",o="beforeunload",r=e=>(e.preventDefault(),e.returnValue=""),i=()=>{removeEventListener(o,r,{capture:!0})};function s(e){let t=e.getLocation(),n=new Set,s=[],h=[];const c=()=>{t=e.getLocation(),n.forEach((e=>e()))},d=()=>{if(s.length)s[0]?.(d,(()=>{s=[],i()}));else for(;h.length;)h.shift()?.()},u=e=>{h.push(e),d()};return{get location(){return t},subscribe:e=>(n.add(e),()=>{n.delete(e)}),push:(t,n)=>{n=a(n),u((()=>{e.pushState(t,n,c)}))},replace:(t,n)=>{n=a(n),u((()=>{e.replaceState(t,n,c)}))},go:t=>{u((()=>{e.go(t)}))},back:()=>{u((()=>{e.back()}))},forward:()=>{u((()=>{e.forward()}))},createHref:t=>e.createHref(t),block:e=>(s.push(e),1===s.length&&addEventListener(o,r,{capture:!0}),()=>{s=s.filter((t=>t!==e)),s.length||i()}),flush:()=>e.flush?.(),destroy:()=>e.destroy?.(),notify:c}}function a(e){return e||(e={}),e.key=d(),e}function h(e){const o=e?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=e?.createHref??(e=>e);let i=c(o(),window.history.state);let a,h,d=!0;const u=()=>{d=!1,(()=>{a&&(window.history[a.isPush?"pushState":"replaceState"](a.state,"",a.href),a=void 0,h=void 0)})(),d=!0},f=(e,t,n,o)=>{const s=r(t);i=c(s,n),a={href:s,state:n,isPush:a?.isPush||"push"===e},o(),h||(h=Promise.resolve().then((()=>u())))},l=()=>{i=c(o(),window.history.state),y.notify()};var w=window.history.pushState,p=window.history.replaceState;const y=s({getLocation:()=>i,pushState:(e,t,n)=>f("push",e,t,n),replaceState:(e,t,n)=>f("replace",e,t,n),back:()=>window.history.back(),forward:()=>window.history.forward(),go:e=>window.history.go(e),createHref:e=>r(e),flush:u,destroy:()=>{window.history.pushState=w,window.history.replaceState=p,window.removeEventListener(t,l),window.removeEventListener(n,l)}});return window.addEventListener(t,l),window.addEventListener(n,l),window.history.pushState=function(){let e=w.apply(window.history,arguments);return d&&y.notify(),e},window.history.replaceState=function(){let e=p.apply(window.history,arguments);return d&&y.notify(),e},y}function c(e,t){let n=e.indexOf("#"),o=e.indexOf("?");return{href:e,pathname:e.substring(0,n>0?o>0?Math.min(n,o):n:o>0?o:e.length),hash:n>-1?e.substring(n):"",search:o>-1?e.slice(o,-1===n?void 0:n):"",state:t||{}}}function d(){return(Math.random()+1).toString(36).substring(7)}e.createBrowserHistory=h,e.createHashHistory=function(){return h({getHref:()=>window.location.hash.substring(1),createHref:e=>`#${e}`})},e.createMemoryHistory=function(e={initialEntries:["/"]}){const t=e.initialEntries;let n=e.initialIndex??t.length-1,o={key:d()};return s({getLocation:()=>c(t[n],o),pushState:(e,r)=>{o=r,t.push(e),n++},replaceState:(e,r)=>{o=r,t[n]=e},back:()=>{n--},forward:()=>{n=Math.min(n+1,t.length-1)},go:e=>window.history.go(e),createHref:e=>e})},Object.defineProperty(e,"__esModule",{value:!0})}));
12
12
  //# sourceMappingURL=index.production.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.production.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n update: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n\n onUpdate()\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n update: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.update()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.update()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.update()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","update","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","scheduled","tracking","isPush","href","undefined","fn","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","hashIndex","indexOf","searchIndex","substring","Math","min","slice","random","toString","initialEntries","entries","initialIndex","currentState"],"mappings":";;;;;;;;;;uPAoCA,MAAMA,EAAiB,YACjBC,EAAgB,WAChBC,EAAoB,eAEpBC,EAAwBC,IAC5BA,EAAMC,iBAEED,EAAME,YA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MC,EAAU/E,EAAK8E,eACrB,IAAInD,EAAQ3B,EAAKgF,cAAgBD,EAAQpE,OAAS,EAC9CsE,EAAe,CACjB1C,IAAKC,KAKP,OAAOzC,EAAc,CACnBG,YAHkBA,IAAM8C,EAAc+B,EAAQpD,GAASsD,GAIvD1D,UAAWA,CAACH,EAAMC,KAChB4D,EAAe5D,EACf0D,EAAQhE,KAAKK,GACbO,GAAO,EAETF,aAAcA,CAACL,EAAMC,KACnB4D,EAAe5D,EACf0D,EAAQpD,GAASP,CAAI,EAEvBQ,KAAMA,KACJD,GAAO,EAETE,QAASA,KACPF,EAAQ8C,KAAKC,IAAI/C,EAAQ,EAAGoD,EAAQpE,OAAS,EAAE,EAEjDe,GAAKuC,GAAMtB,OAAOM,QAAQvB,GAAGuC,GAC7BnC,WAAaV,GAASA,GAE1B"}
1
+ {"version":3,"file":"index.production.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","scheduled","tracking","isPush","href","undefined","fn","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","hashIndex","indexOf","searchIndex","substring","Math","min","slice","random","toString","initialEntries","entries","initialIndex","currentState"],"mappings":";;;;;;;;;;uPAoCA,MAAMA,EAAiB,YACjBC,EAAgB,WAChBC,EAAoB,eAEpBC,EAAwBC,IAC5BA,EAAMC,iBAEED,EAAME,YAAc,IAGxBC,EAAeA,KACnBC,oBAAoBN,EAAmBC,EAAsB,CAC3DM,SAAS,GACT,EAGJ,SAASC,EAAcC,GAWrB,IAAIC,EAAWD,EAAKE,cAChBC,EAAc,IAAIC,IAClBC,EAAwB,GAC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IvD1D,UAAWA,CAACH,EAAMC,KAChB4D,EAAe5D,EACf0D,EAAQhE,KAAKK,GACbO,GAAO,EAETF,aAAcA,CAACL,EAAMC,KACnB4D,EAAe5D,EACf0D,EAAQpD,GAASP,CAAI,EAEvBQ,KAAMA,KACJD,GAAO,EAETE,QAASA,KACPF,EAAQ8C,KAAKC,IAAI/C,EAAQ,EAAGoD,EAAQpE,OAAS,EAAE,EAEjDe,GAAKuC,GAAMtB,OAAOM,QAAQvB,GAAGuC,GAC7BnC,WAAaV,GAASA,GAE1B"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/history",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.204",
4
+ "version": "0.0.1-beta.206",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/history",
7
7
  "homepage": "https://tanstack.com",
package/src/index.ts CHANGED
@@ -14,7 +14,7 @@ export interface RouterHistory {
14
14
  block: (blockerFn: BlockerFn) => () => void
15
15
  flush: () => void
16
16
  destroy: () => void
17
- update: () => void
17
+ notify: () => void
18
18
  }
19
19
 
20
20
  export interface HistoryLocation extends ParsedPath {
@@ -83,8 +83,6 @@ function createHistory(opts: {
83
83
  while (queue.length) {
84
84
  queue.shift()?.()
85
85
  }
86
-
87
- onUpdate()
88
86
  }
89
87
 
90
88
  const queueTask = (task: () => void) => {
@@ -150,7 +148,7 @@ function createHistory(opts: {
150
148
  },
151
149
  flush: () => opts.flush?.(),
152
150
  destroy: () => opts.destroy?.(),
153
- update: onUpdate,
151
+ notify: onUpdate,
154
152
  }
155
153
  }
156
154
 
@@ -267,7 +265,7 @@ export function createBrowserHistory(opts?: {
267
265
 
268
266
  const onPushPop = () => {
269
267
  currentLocation = parseLocation(getHref(), window.history.state)
270
- history.update()
268
+ history.notify()
271
269
  }
272
270
 
273
271
  var originalPushState = window.history.pushState
@@ -297,13 +295,13 @@ export function createBrowserHistory(opts?: {
297
295
 
298
296
  window.history.pushState = function () {
299
297
  let res = originalPushState.apply(window.history, arguments as any)
300
- if (tracking) history.update()
298
+ if (tracking) history.notify()
301
299
  return res
302
300
  }
303
301
 
304
302
  window.history.replaceState = function () {
305
303
  let res = originalReplaceState.apply(window.history, arguments as any)
306
- if (tracking) history.update()
304
+ if (tracking) history.notify()
307
305
  return res
308
306
  }
309
307