@tanstack/solid-router 1.114.1 → 1.114.3

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.
@@ -28,7 +28,8 @@ const scrollRestorationCache = sessionsStorage ? (() => {
28
28
  // This setter is simply to make sure that we set the sessionStorage right
29
29
  // after the state is updated. It doesn't necessarily need to be a functional
30
30
  // update.
31
- set: (updater) => (scrollRestorationCache.state = routerCore.functionalUpdate(updater, scrollRestorationCache.state) || scrollRestorationCache.state, window.sessionStorage.setItem(storageKey, JSON.stringify(scrollRestorationCache.state)))
31
+ set: (updater) => (scrollRestorationCache.state = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
32
+ routerCore.functionalUpdate(updater, scrollRestorationCache.state) || scrollRestorationCache.state, window.sessionStorage.setItem(storageKey, JSON.stringify(scrollRestorationCache.state)))
32
33
  };
33
34
  })() : void 0;
34
35
  const defaultGetScrollRestorationKey = (location) => {
@@ -153,7 +154,7 @@ function setupScrollRestoration(router, force) {
153
154
  router.resetNextScroll = true;
154
155
  return;
155
156
  }
156
- restoreScroll(storageKey, cacheKey, router.options.scrollRestorationBehavior, router.isScrollRestoring, router.options.scrollToTopSelectors);
157
+ restoreScroll(storageKey, cacheKey, router.options.scrollRestorationBehavior || void 0, router.isScrollRestoring || void 0, router.options.scrollToTopSelectors || void 0);
157
158
  if (router.isScrollRestoring) {
158
159
  scrollRestorationCache.set((state) => {
159
160
  state[cacheKey] = state[cacheKey] || {};
@@ -1 +1 @@
1
- {"version":3,"file":"scroll-restoration.cjs","sources":["../../src/scroll-restoration.tsx"],"sourcesContent":["import { functionalUpdate } from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport { ScriptOnce } from './ScriptOnce'\n\nimport type {\n AnyRouter,\n NonNullableUpdater,\n ParsedLocation,\n} from '@tanstack/router-core'\n\nexport type ScrollRestorationEntry = { scrollX: number; scrollY: number }\n\nexport type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>\n\nexport type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>\n\nexport type ScrollRestorationCache = {\n state: ScrollRestorationByKey\n set: (updater: NonNullableUpdater<ScrollRestorationByKey>) => void\n}\nexport type ScrollRestorationOptions = {\n getKey?: (location: ParsedLocation) => string\n scrollBehavior?: ScrollToOptions['behavior']\n}\n\nexport const storageKey = 'tsr-scroll-restoration-v1_3'\nlet sessionsStorage = false\ntry {\n sessionsStorage =\n typeof window !== 'undefined' && typeof window.sessionStorage === 'object'\n} catch {}\nconst throttle = (fn: (...args: Array<any>) => void, wait: number) => {\n let timeout: any\n return (...args: Array<any>) => {\n if (!timeout) {\n timeout = setTimeout(() => {\n fn(...args)\n timeout = null\n }, wait)\n }\n }\n}\nexport const scrollRestorationCache: ScrollRestorationCache = sessionsStorage\n ? (() => {\n const state: ScrollRestorationByKey =\n JSON.parse(window.sessionStorage.getItem(storageKey) || 'null') || {}\n\n return {\n state,\n // This setter is simply to make sure that we set the sessionStorage right\n // after the state is updated. It doesn't necessarily need to be a functional\n // update.\n set: (updater) => (\n (scrollRestorationCache.state =\n functionalUpdate(updater, scrollRestorationCache.state) ||\n scrollRestorationCache.state),\n window.sessionStorage.setItem(\n storageKey,\n JSON.stringify(scrollRestorationCache.state),\n )\n ),\n }\n })()\n : (undefined as any)\n/**\n * The default `getKey` function for `useScrollRestoration`.\n * It returns the `key` from the location state or the `href` of the location.\n *\n * The `location.href` is used as a fallback to support the use case where the location state is not available like the initial render.\n */\n\nexport const defaultGetScrollRestorationKey = (location: ParsedLocation) => {\n return location.state.key! || location.href\n}\n\nexport function getCssSelector(el: any): string {\n const path = []\n let parent\n while ((parent = el.parentNode)) {\n path.unshift(\n `${el.tagName}:nth-child(${([].indexOf as any).call(parent.children, el) + 1})`,\n )\n el = parent\n }\n return `${path.join(' > ')}`.toLowerCase()\n}\n\nlet ignoreScroll = false\n\n// NOTE: This function must remain pure and not use any outside variables\n// unless they are passed in as arguments. Why? Because we need to be able to\n// toString() it into a script tag to execute as early as possible in the browser\n// during SSR. Additionally, we also call it from within the router lifecycle\nexport function restoreScroll(\n storageKey: string,\n key?: string,\n behavior?: ScrollToOptions['behavior'],\n shouldScrollRestoration?: boolean,\n scrollToTopSelectors?: Array<string>,\n) {\n let byKey: ScrollRestorationByKey\n\n try {\n byKey = JSON.parse(sessionStorage.getItem(storageKey) || '{}')\n } catch (error: any) {\n console.error(error)\n return\n }\n\n const resolvedKey = key || window.history.state?.key\n const elementEntries = byKey[resolvedKey]\n\n //\n ignoreScroll = true\n\n //\n ;(() => {\n // If we have a cached entry for this location state,\n // we always need to prefer that over the hash scroll.\n if (shouldScrollRestoration && elementEntries) {\n for (const elementSelector in elementEntries) {\n const entry = elementEntries[elementSelector]!\n if (elementSelector === 'window') {\n window.scrollTo({\n top: entry.scrollY,\n left: entry.scrollX,\n behavior,\n })\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n element.scrollLeft = entry.scrollX\n element.scrollTop = entry.scrollY\n }\n }\n }\n\n return\n }\n\n // If we don't have a cached entry for the hash,\n // Which means we've never seen this location before,\n // we need to check if there is a hash in the URL.\n // If there is, we need to scroll it's ID into view.\n const hash = window.location.hash.split('#')[1]\n\n if (hash) {\n const hashScrollIntoViewOptions =\n (window.history.state || {}).__hashScrollIntoViewOptions ?? true\n\n if (hashScrollIntoViewOptions) {\n const el = document.getElementById(hash)\n if (el) {\n el.scrollIntoView(hashScrollIntoViewOptions)\n }\n }\n\n return\n }\n\n // If there is no cached entry for the hash and there is no hash in the URL,\n // we need to scroll to the top of the page for every scrollToTop element\n ;[\n 'window',\n ...(scrollToTopSelectors?.filter((d) => d !== 'window') ?? []),\n ].forEach((selector) => {\n const element =\n selector === 'window' ? window : document.querySelector(selector)\n if (element) {\n element.scrollTo({\n top: 0,\n left: 0,\n behavior,\n })\n }\n })\n })()\n\n //\n ignoreScroll = false\n}\n\nexport function setupScrollRestoration(router: AnyRouter, force?: boolean) {\n const shouldScrollRestoration =\n force ?? router.options.scrollRestoration ?? false\n\n if (shouldScrollRestoration) {\n router.isScrollRestoring = true\n }\n\n if (typeof document === 'undefined' || router.isScrollRestorationSetup) {\n return\n }\n\n router.isScrollRestorationSetup = true\n\n //\n ignoreScroll = false\n\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n\n window.history.scrollRestoration = 'manual'\n\n // // Create a MutationObserver to monitor DOM changes\n // const mutationObserver = new MutationObserver(() => {\n // ;ignoreScroll = true\n // requestAnimationFrame(() => {\n // ;ignoreScroll = false\n\n // // Attempt to restore scroll position on each dom\n // // mutation until the user scrolls. We do this\n // // because dynamic content may come in at different\n // // ticks after the initial render and we want to\n // // keep up with that content as much as possible.\n // // As soon as the user scrolls, we no longer need\n // // to attempt router.\n // // console.log('mutation observer restoreScroll')\n // restoreScroll(\n // storageKey,\n // getKey(router.state.location),\n // router.options.scrollRestorationBehavior,\n // )\n // })\n // })\n\n // const observeDom = () => {\n // // Observe changes to the entire document\n // mutationObserver.observe(document, {\n // childList: true, // Detect added or removed child nodes\n // subtree: true, // Monitor all descendants\n // characterData: true, // Detect text content changes\n // })\n // }\n\n // const unobserveDom = () => {\n // mutationObserver.disconnect()\n // }\n\n // observeDom()\n\n const onScroll = (event: Event) => {\n // unobserveDom()\n\n if (ignoreScroll || !router.isScrollRestoring) {\n return\n }\n\n let elementSelector = ''\n\n if (event.target === document || event.target === window) {\n elementSelector = 'window'\n } else {\n const attrId = (event.target as Element).getAttribute(\n 'data-scroll-restoration-id',\n )\n\n if (attrId) {\n elementSelector = `[data-scroll-restoration-id=\"${attrId}\"]`\n } else {\n elementSelector = getCssSelector(event.target)\n }\n }\n\n const restoreKey = getKey(router.state.location)\n\n scrollRestorationCache.set((state) => {\n const keyEntry = (state[restoreKey] =\n state[restoreKey] || ({} as ScrollRestorationByElement))\n\n const elementEntry = (keyEntry[elementSelector] =\n keyEntry[elementSelector] || ({} as ScrollRestorationEntry))\n\n if (elementSelector === 'window') {\n elementEntry.scrollX = window.scrollX || 0\n elementEntry.scrollY = window.scrollY || 0\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n elementEntry.scrollX = element.scrollLeft || 0\n elementEntry.scrollY = element.scrollTop || 0\n }\n }\n\n return state\n })\n }\n\n // Throttle the scroll event to avoid excessive updates\n if (typeof document !== 'undefined') {\n document.addEventListener('scroll', throttle(onScroll, 100), true)\n }\n\n router.subscribe('onRendered', (event) => {\n // unobserveDom()\n\n const cacheKey = getKey(event.toLocation)\n\n // If the user doesn't want to restore the scroll position,\n // we don't need to do anything.\n if (!router.resetNextScroll) {\n router.resetNextScroll = true\n return\n }\n\n restoreScroll(\n storageKey,\n cacheKey,\n router.options.scrollRestorationBehavior,\n router.isScrollRestoring,\n router.options.scrollToTopSelectors,\n )\n\n if (router.isScrollRestoring) {\n // Mark the location as having been seen\n scrollRestorationCache.set((state) => {\n state[cacheKey] = state[cacheKey] || ({} as ScrollRestorationByElement)\n\n return state\n })\n }\n })\n}\n\nexport function ScrollRestoration() {\n const router = useRouter()\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n const userKey = getKey(router.latestLocation)\n const resolvedKey =\n userKey !== defaultGetScrollRestorationKey(router.latestLocation)\n ? userKey\n : null\n\n if (!router.isScrollRestoring || !router.isServer) {\n return null\n }\n\n return (\n <ScriptOnce\n children={`(${restoreScroll.toString()})(${JSON.stringify(storageKey)},${JSON.stringify(resolvedKey)}, undefined, true)`}\n log={false}\n />\n )\n}\n"],"names":["storageKey","sessionsStorage","window","sessionStorage","throttle","fn","wait","timeout","args","setTimeout","scrollRestorationCache","state","JSON","parse","getItem","set","updater","functionalUpdate","setItem","stringify","undefined","defaultGetScrollRestorationKey","location","key","href","getCssSelector","el","path","parent","parentNode","unshift","tagName","indexOf","call","children","join","toLowerCase","ignoreScroll","restoreScroll","behavior","shouldScrollRestoration","scrollToTopSelectors","byKey","error","console","resolvedKey","history","elementEntries","elementSelector","entry","scrollTo","top","scrollY","left","scrollX","element","document","querySelector","scrollLeft","scrollTop","hash","split","hashScrollIntoViewOptions","__hashScrollIntoViewOptions","getElementById","scrollIntoView","filter","d","forEach","selector","setupScrollRestoration","router","force","options","scrollRestoration","isScrollRestoring","isScrollRestorationSetup","getKey","getScrollRestorationKey","onScroll","event","target","attrId","getAttribute","restoreKey","keyEntry","elementEntry","addEventListener","subscribe","cacheKey","toLocation","resetNextScroll","scrollRestorationBehavior","ScrollRestoration","useRouter","userKey","latestLocation","isServer","_$createComponent","ScriptOnce","toString","log"],"mappings":";;;;;;AAyBO,MAAMA,aAAa;AAC1B,IAAIC,kBAAkB;AACtB,IAAI;AACFA,oBACE,OAAOC,WAAW,eAAe,OAAOA,OAAOC,mBAAmB;AACtE,QAAQ;AAAC;AACT,MAAMC,WAAWA,CAACC,IAAmCC,SAAiB;AAChEC,MAAAA;AACJ,SAAO,IAAIC,SAAqB;AAC9B,QAAI,CAACD,SAAS;AACZA,gBAAUE,WAAW,MAAM;AACzBJ,WAAG,GAAGG,IAAI;AACA,kBAAA;AAAA,SACTF,IAAI;AAAA,IAAA;AAAA,EAEX;AACF;AACaI,MAAAA,yBAAiDT,mBACzD,MAAM;AACCU,QAAAA,QACJC,KAAKC,MAAMX,OAAOC,eAAeW,QAAQd,UAAU,KAAK,MAAM,KAAK,CAAC;AAE/D,SAAA;AAAA,IACLW;AAAAA;AAAAA;AAAAA;AAAAA,IAIAI,KAAMC,CACHN,aAAAA,uBAAuBC,QACtBM,WAAAA,iBAAiBD,SAASN,uBAAuBC,KAAK,KACtDD,uBAAuBC,OACzBT,OAAOC,eAAee,QACpBlB,YACAY,KAAKO,UAAUT,uBAAuBC,KAAK,CAC7C;AAAA,EAEJ;AACF,OACCS;AAQQC,MAAAA,iCAAiCA,CAACC,aAA6B;AACnEA,SAAAA,SAASX,MAAMY,OAAQD,SAASE;AACzC;AAEO,SAASC,eAAeC,IAAiB;AAC9C,QAAMC,OAAO,CAAE;AACXC,MAAAA;AACIA,SAAAA,SAASF,GAAGG,YAAa;AA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,cACJkD,YAAY1E,+BAA+BkD,OAAOyB,cAAc,IAC5DD,UACA;AAEN,MAAI,CAACxB,OAAOI,qBAAqB,CAACJ,OAAO0B,UAAU;AAC1C,WAAA;AAAA,EAAA;AAGT,SAAAC,IAAAA,gBACGC,WAAAA,YAAU;AAAA,IAAA,IACTjE,WAAQ;AAAA,aAAE,IAAII,cAAc8D,SAAS,CAAC,KAAKxF,KAAKO,UAAUnB,UAAU,CAAC,IAAIY,KAAKO,UAAU0B,WAAW,CAAC;AAAA,IAAoB;AAAA,IACxHwD,KAAK;AAAA,EAAA,CAAK;AAGhB;;;;;;;;"}
1
+ {"version":3,"file":"scroll-restoration.cjs","sources":["../../src/scroll-restoration.tsx"],"sourcesContent":["import { functionalUpdate } from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport { ScriptOnce } from './ScriptOnce'\n\nimport type {\n AnyRouter,\n NonNullableUpdater,\n ParsedLocation,\n} from '@tanstack/router-core'\n\nexport type ScrollRestorationEntry = { scrollX: number; scrollY: number }\n\nexport type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>\n\nexport type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>\n\nexport type ScrollRestorationCache = {\n state: ScrollRestorationByKey\n set: (updater: NonNullableUpdater<ScrollRestorationByKey>) => void\n}\nexport type ScrollRestorationOptions = {\n getKey?: (location: ParsedLocation) => string\n scrollBehavior?: ScrollToOptions['behavior']\n}\n\nexport const storageKey = 'tsr-scroll-restoration-v1_3'\nlet sessionsStorage = false\ntry {\n sessionsStorage =\n typeof window !== 'undefined' && typeof window.sessionStorage === 'object'\n} catch {}\nconst throttle = (fn: (...args: Array<any>) => void, wait: number) => {\n let timeout: any\n return (...args: Array<any>) => {\n if (!timeout) {\n timeout = setTimeout(() => {\n fn(...args)\n timeout = null\n }, wait)\n }\n }\n}\nexport const scrollRestorationCache: ScrollRestorationCache = sessionsStorage\n ? (() => {\n const state: ScrollRestorationByKey =\n JSON.parse(window.sessionStorage.getItem(storageKey) || 'null') || {}\n\n return {\n state,\n // This setter is simply to make sure that we set the sessionStorage right\n // after the state is updated. It doesn't necessarily need to be a functional\n // update.\n set: (updater) => (\n (scrollRestorationCache.state =\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n functionalUpdate(updater, scrollRestorationCache.state) ||\n scrollRestorationCache.state),\n window.sessionStorage.setItem(\n storageKey,\n JSON.stringify(scrollRestorationCache.state),\n )\n ),\n }\n })()\n : (undefined as any)\n/**\n * The default `getKey` function for `useScrollRestoration`.\n * It returns the `key` from the location state or the `href` of the location.\n *\n * The `location.href` is used as a fallback to support the use case where the location state is not available like the initial render.\n */\n\nexport const defaultGetScrollRestorationKey = (location: ParsedLocation) => {\n return location.state.key! || location.href\n}\n\nexport function getCssSelector(el: any): string {\n const path = []\n let parent\n while ((parent = el.parentNode)) {\n path.unshift(\n `${el.tagName}:nth-child(${([].indexOf as any).call(parent.children, el) + 1})`,\n )\n el = parent\n }\n return `${path.join(' > ')}`.toLowerCase()\n}\n\nlet ignoreScroll = false\n\n// NOTE: This function must remain pure and not use any outside variables\n// unless they are passed in as arguments. Why? Because we need to be able to\n// toString() it into a script tag to execute as early as possible in the browser\n// during SSR. Additionally, we also call it from within the router lifecycle\nexport function restoreScroll(\n storageKey: string,\n key: string | undefined,\n behavior: ScrollToOptions['behavior'] | undefined,\n shouldScrollRestoration: boolean | undefined,\n scrollToTopSelectors: Array<string> | undefined,\n) {\n let byKey: ScrollRestorationByKey\n\n try {\n byKey = JSON.parse(sessionStorage.getItem(storageKey) || '{}')\n } catch (error: any) {\n console.error(error)\n return\n }\n\n const resolvedKey = key || window.history.state?.key\n const elementEntries = byKey[resolvedKey]\n\n //\n ignoreScroll = true\n\n //\n ;(() => {\n // If we have a cached entry for this location state,\n // we always need to prefer that over the hash scroll.\n if (shouldScrollRestoration && elementEntries) {\n for (const elementSelector in elementEntries) {\n const entry = elementEntries[elementSelector]!\n if (elementSelector === 'window') {\n window.scrollTo({\n top: entry.scrollY,\n left: entry.scrollX,\n behavior,\n })\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n element.scrollLeft = entry.scrollX\n element.scrollTop = entry.scrollY\n }\n }\n }\n\n return\n }\n\n // If we don't have a cached entry for the hash,\n // Which means we've never seen this location before,\n // we need to check if there is a hash in the URL.\n // If there is, we need to scroll it's ID into view.\n const hash = window.location.hash.split('#')[1]\n\n if (hash) {\n const hashScrollIntoViewOptions =\n (window.history.state || {}).__hashScrollIntoViewOptions ?? true\n\n if (hashScrollIntoViewOptions) {\n const el = document.getElementById(hash)\n if (el) {\n el.scrollIntoView(hashScrollIntoViewOptions)\n }\n }\n\n return\n }\n\n // If there is no cached entry for the hash and there is no hash in the URL,\n // we need to scroll to the top of the page for every scrollToTop element\n ;[\n 'window',\n ...(scrollToTopSelectors?.filter((d) => d !== 'window') ?? []),\n ].forEach((selector) => {\n const element =\n selector === 'window' ? window : document.querySelector(selector)\n if (element) {\n element.scrollTo({\n top: 0,\n left: 0,\n behavior,\n })\n }\n })\n })()\n\n //\n ignoreScroll = false\n}\n\nexport function setupScrollRestoration(router: AnyRouter, force?: boolean) {\n const shouldScrollRestoration =\n force ?? router.options.scrollRestoration ?? false\n\n if (shouldScrollRestoration) {\n router.isScrollRestoring = true\n }\n\n if (typeof document === 'undefined' || router.isScrollRestorationSetup) {\n return\n }\n\n router.isScrollRestorationSetup = true\n\n //\n ignoreScroll = false\n\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n\n window.history.scrollRestoration = 'manual'\n\n // // Create a MutationObserver to monitor DOM changes\n // const mutationObserver = new MutationObserver(() => {\n // ;ignoreScroll = true\n // requestAnimationFrame(() => {\n // ;ignoreScroll = false\n\n // // Attempt to restore scroll position on each dom\n // // mutation until the user scrolls. We do this\n // // because dynamic content may come in at different\n // // ticks after the initial render and we want to\n // // keep up with that content as much as possible.\n // // As soon as the user scrolls, we no longer need\n // // to attempt router.\n // // console.log('mutation observer restoreScroll')\n // restoreScroll(\n // storageKey,\n // getKey(router.state.location),\n // router.options.scrollRestorationBehavior,\n // )\n // })\n // })\n\n // const observeDom = () => {\n // // Observe changes to the entire document\n // mutationObserver.observe(document, {\n // childList: true, // Detect added or removed child nodes\n // subtree: true, // Monitor all descendants\n // characterData: true, // Detect text content changes\n // })\n // }\n\n // const unobserveDom = () => {\n // mutationObserver.disconnect()\n // }\n\n // observeDom()\n\n const onScroll = (event: Event) => {\n // unobserveDom()\n\n if (ignoreScroll || !router.isScrollRestoring) {\n return\n }\n\n let elementSelector = ''\n\n if (event.target === document || event.target === window) {\n elementSelector = 'window'\n } else {\n const attrId = (event.target as Element).getAttribute(\n 'data-scroll-restoration-id',\n )\n\n if (attrId) {\n elementSelector = `[data-scroll-restoration-id=\"${attrId}\"]`\n } else {\n elementSelector = getCssSelector(event.target)\n }\n }\n\n const restoreKey = getKey(router.state.location)\n\n scrollRestorationCache.set((state) => {\n const keyEntry = (state[restoreKey] =\n state[restoreKey] || ({} as ScrollRestorationByElement))\n\n const elementEntry = (keyEntry[elementSelector] =\n keyEntry[elementSelector] || ({} as ScrollRestorationEntry))\n\n if (elementSelector === 'window') {\n elementEntry.scrollX = window.scrollX || 0\n elementEntry.scrollY = window.scrollY || 0\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n elementEntry.scrollX = element.scrollLeft || 0\n elementEntry.scrollY = element.scrollTop || 0\n }\n }\n\n return state\n })\n }\n\n // Throttle the scroll event to avoid excessive updates\n if (typeof document !== 'undefined') {\n document.addEventListener('scroll', throttle(onScroll, 100), true)\n }\n\n router.subscribe('onRendered', (event) => {\n // unobserveDom()\n\n const cacheKey = getKey(event.toLocation)\n\n // If the user doesn't want to restore the scroll position,\n // we don't need to do anything.\n if (!router.resetNextScroll) {\n router.resetNextScroll = true\n return\n }\n\n restoreScroll(\n storageKey,\n cacheKey,\n router.options.scrollRestorationBehavior || undefined,\n router.isScrollRestoring || undefined,\n router.options.scrollToTopSelectors || undefined,\n )\n\n if (router.isScrollRestoring) {\n // Mark the location as having been seen\n scrollRestorationCache.set((state) => {\n state[cacheKey] = state[cacheKey] || ({} as ScrollRestorationByElement)\n\n return state\n })\n }\n })\n}\n\nexport function ScrollRestoration() {\n const router = useRouter()\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n const userKey = getKey(router.latestLocation)\n const resolvedKey =\n userKey !== defaultGetScrollRestorationKey(router.latestLocation)\n ? userKey\n : null\n\n if (!router.isScrollRestoring || !router.isServer) {\n return null\n }\n\n return (\n <ScriptOnce\n children={`(${restoreScroll.toString()})(${JSON.stringify(storageKey)},${JSON.stringify(resolvedKey)}, undefined, true)`}\n log={false}\n />\n )\n}\n"],"names":["storageKey","sessionsStorage","window","sessionStorage","throttle","fn","wait","timeout","args","setTimeout","scrollRestorationCache","state","JSON","parse","getItem","set","updater","functionalUpdate","setItem","stringify","undefined","defaultGetScrollRestorationKey","location","key","href","getCssSelector","el","path","parent","parentNode","unshift","tagName","indexOf","call","children","join","toLowerCase","ignoreScroll","restoreScroll","behavior","shouldScrollRestoration","scrollToTopSelectors","byKey","error","console","resolvedKey","history","elementEntries","elementSelector","entry","scrollTo","top","scrollY","left","scrollX","element","document","querySelector","scrollLeft","scrollTop","hash","split","hashScrollIntoViewOptions","__hashScrollIntoViewOptions","getElementById","scrollIntoView","filter","d","forEach","selector","setupScrollRestoration","router","force","options","scrollRestoration","isScrollRestoring","isScrollRestorationSetup","getKey","getScrollRestorationKey","onScroll","event","target","attrId","getAttribute","restoreKey","keyEntry","elementEntry","addEventListener","subscribe","cacheKey","toLocation","resetNextScroll","scrollRestorationBehavior","ScrollRestoration","useRouter","userKey","latestLocation","isServer","_$createComponent","ScriptOnce","toString","log"],"mappings":";;;;;;AAyBO,MAAMA,aAAa;AAC1B,IAAIC,kBAAkB;AACtB,IAAI;AACFA,oBACE,OAAOC,WAAW,eAAe,OAAOA,OAAOC,mBAAmB;AACtE,QAAQ;AAAC;AACT,MAAMC,WAAWA,CAACC,IA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  export declare const defaultGetScrollRestorationKey: (location: ParsedLocation) => string;
25
25
  export declare function getCssSelector(el: any): string;
26
- export declare function restoreScroll(storageKey: string, key?: string, behavior?: ScrollToOptions['behavior'], shouldScrollRestoration?: boolean, scrollToTopSelectors?: Array<string>): void;
26
+ export declare function restoreScroll(storageKey: string, key: string | undefined, behavior: ScrollToOptions['behavior'] | undefined, shouldScrollRestoration: boolean | undefined, scrollToTopSelectors: Array<string> | undefined): void;
27
27
  export declare function setupScrollRestoration(router: AnyRouter, force?: boolean): void;
28
28
  export declare function ScrollRestoration(): import("solid-js").JSX.Element;
@@ -23,6 +23,6 @@ export declare const scrollRestorationCache: ScrollRestorationCache;
23
23
  */
24
24
  export declare const defaultGetScrollRestorationKey: (location: ParsedLocation) => string;
25
25
  export declare function getCssSelector(el: any): string;
26
- export declare function restoreScroll(storageKey: string, key?: string, behavior?: ScrollToOptions['behavior'], shouldScrollRestoration?: boolean, scrollToTopSelectors?: Array<string>): void;
26
+ export declare function restoreScroll(storageKey: string, key: string | undefined, behavior: ScrollToOptions['behavior'] | undefined, shouldScrollRestoration: boolean | undefined, scrollToTopSelectors: Array<string> | undefined): void;
27
27
  export declare function setupScrollRestoration(router: AnyRouter, force?: boolean): void;
28
28
  export declare function ScrollRestoration(): import("solid-js").JSX.Element;
@@ -26,7 +26,8 @@ const scrollRestorationCache = sessionsStorage ? (() => {
26
26
  // This setter is simply to make sure that we set the sessionStorage right
27
27
  // after the state is updated. It doesn't necessarily need to be a functional
28
28
  // update.
29
- set: (updater) => (scrollRestorationCache.state = functionalUpdate(updater, scrollRestorationCache.state) || scrollRestorationCache.state, window.sessionStorage.setItem(storageKey, JSON.stringify(scrollRestorationCache.state)))
29
+ set: (updater) => (scrollRestorationCache.state = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
30
+ functionalUpdate(updater, scrollRestorationCache.state) || scrollRestorationCache.state, window.sessionStorage.setItem(storageKey, JSON.stringify(scrollRestorationCache.state)))
30
31
  };
31
32
  })() : void 0;
32
33
  const defaultGetScrollRestorationKey = (location) => {
@@ -151,7 +152,7 @@ function setupScrollRestoration(router, force) {
151
152
  router.resetNextScroll = true;
152
153
  return;
153
154
  }
154
- restoreScroll(storageKey, cacheKey, router.options.scrollRestorationBehavior, router.isScrollRestoring, router.options.scrollToTopSelectors);
155
+ restoreScroll(storageKey, cacheKey, router.options.scrollRestorationBehavior || void 0, router.isScrollRestoring || void 0, router.options.scrollToTopSelectors || void 0);
155
156
  if (router.isScrollRestoring) {
156
157
  scrollRestorationCache.set((state) => {
157
158
  state[cacheKey] = state[cacheKey] || {};
@@ -1 +1 @@
1
- {"version":3,"file":"scroll-restoration.js","sources":["../../src/scroll-restoration.tsx"],"sourcesContent":["import { functionalUpdate } from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport { ScriptOnce } from './ScriptOnce'\n\nimport type {\n AnyRouter,\n NonNullableUpdater,\n ParsedLocation,\n} from '@tanstack/router-core'\n\nexport type ScrollRestorationEntry = { scrollX: number; scrollY: number }\n\nexport type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>\n\nexport type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>\n\nexport type ScrollRestorationCache = {\n state: ScrollRestorationByKey\n set: (updater: NonNullableUpdater<ScrollRestorationByKey>) => void\n}\nexport type ScrollRestorationOptions = {\n getKey?: (location: ParsedLocation) => string\n scrollBehavior?: ScrollToOptions['behavior']\n}\n\nexport const storageKey = 'tsr-scroll-restoration-v1_3'\nlet sessionsStorage = false\ntry {\n sessionsStorage =\n typeof window !== 'undefined' && typeof window.sessionStorage === 'object'\n} catch {}\nconst throttle = (fn: (...args: Array<any>) => void, wait: number) => {\n let timeout: any\n return (...args: Array<any>) => {\n if (!timeout) {\n timeout = setTimeout(() => {\n fn(...args)\n timeout = null\n }, wait)\n }\n }\n}\nexport const scrollRestorationCache: ScrollRestorationCache = sessionsStorage\n ? (() => {\n const state: ScrollRestorationByKey =\n JSON.parse(window.sessionStorage.getItem(storageKey) || 'null') || {}\n\n return {\n state,\n // This setter is simply to make sure that we set the sessionStorage right\n // after the state is updated. It doesn't necessarily need to be a functional\n // update.\n set: (updater) => (\n (scrollRestorationCache.state =\n functionalUpdate(updater, scrollRestorationCache.state) ||\n scrollRestorationCache.state),\n window.sessionStorage.setItem(\n storageKey,\n JSON.stringify(scrollRestorationCache.state),\n )\n ),\n }\n })()\n : (undefined as any)\n/**\n * The default `getKey` function for `useScrollRestoration`.\n * It returns the `key` from the location state or the `href` of the location.\n *\n * The `location.href` is used as a fallback to support the use case where the location state is not available like the initial render.\n */\n\nexport const defaultGetScrollRestorationKey = (location: ParsedLocation) => {\n return location.state.key! || location.href\n}\n\nexport function getCssSelector(el: any): string {\n const path = []\n let parent\n while ((parent = el.parentNode)) {\n path.unshift(\n `${el.tagName}:nth-child(${([].indexOf as any).call(parent.children, el) + 1})`,\n )\n el = parent\n }\n return `${path.join(' > ')}`.toLowerCase()\n}\n\nlet ignoreScroll = false\n\n// NOTE: This function must remain pure and not use any outside variables\n// unless they are passed in as arguments. Why? Because we need to be able to\n// toString() it into a script tag to execute as early as possible in the browser\n// during SSR. Additionally, we also call it from within the router lifecycle\nexport function restoreScroll(\n storageKey: string,\n key?: string,\n behavior?: ScrollToOptions['behavior'],\n shouldScrollRestoration?: boolean,\n scrollToTopSelectors?: Array<string>,\n) {\n let byKey: ScrollRestorationByKey\n\n try {\n byKey = JSON.parse(sessionStorage.getItem(storageKey) || '{}')\n } catch (error: any) {\n console.error(error)\n return\n }\n\n const resolvedKey = key || window.history.state?.key\n const elementEntries = byKey[resolvedKey]\n\n //\n ignoreScroll = true\n\n //\n ;(() => {\n // If we have a cached entry for this location state,\n // we always need to prefer that over the hash scroll.\n if (shouldScrollRestoration && elementEntries) {\n for (const elementSelector in elementEntries) {\n const entry = elementEntries[elementSelector]!\n if (elementSelector === 'window') {\n window.scrollTo({\n top: entry.scrollY,\n left: entry.scrollX,\n behavior,\n })\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n element.scrollLeft = entry.scrollX\n element.scrollTop = entry.scrollY\n }\n }\n }\n\n return\n }\n\n // If we don't have a cached entry for the hash,\n // Which means we've never seen this location before,\n // we need to check if there is a hash in the URL.\n // If there is, we need to scroll it's ID into view.\n const hash = window.location.hash.split('#')[1]\n\n if (hash) {\n const hashScrollIntoViewOptions =\n (window.history.state || {}).__hashScrollIntoViewOptions ?? true\n\n if (hashScrollIntoViewOptions) {\n const el = document.getElementById(hash)\n if (el) {\n el.scrollIntoView(hashScrollIntoViewOptions)\n }\n }\n\n return\n }\n\n // If there is no cached entry for the hash and there is no hash in the URL,\n // we need to scroll to the top of the page for every scrollToTop element\n ;[\n 'window',\n ...(scrollToTopSelectors?.filter((d) => d !== 'window') ?? []),\n ].forEach((selector) => {\n const element =\n selector === 'window' ? window : document.querySelector(selector)\n if (element) {\n element.scrollTo({\n top: 0,\n left: 0,\n behavior,\n })\n }\n })\n })()\n\n //\n ignoreScroll = false\n}\n\nexport function setupScrollRestoration(router: AnyRouter, force?: boolean) {\n const shouldScrollRestoration =\n force ?? router.options.scrollRestoration ?? false\n\n if (shouldScrollRestoration) {\n router.isScrollRestoring = true\n }\n\n if (typeof document === 'undefined' || router.isScrollRestorationSetup) {\n return\n }\n\n router.isScrollRestorationSetup = true\n\n //\n ignoreScroll = false\n\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n\n window.history.scrollRestoration = 'manual'\n\n // // Create a MutationObserver to monitor DOM changes\n // const mutationObserver = new MutationObserver(() => {\n // ;ignoreScroll = true\n // requestAnimationFrame(() => {\n // ;ignoreScroll = false\n\n // // Attempt to restore scroll position on each dom\n // // mutation until the user scrolls. We do this\n // // because dynamic content may come in at different\n // // ticks after the initial render and we want to\n // // keep up with that content as much as possible.\n // // As soon as the user scrolls, we no longer need\n // // to attempt router.\n // // console.log('mutation observer restoreScroll')\n // restoreScroll(\n // storageKey,\n // getKey(router.state.location),\n // router.options.scrollRestorationBehavior,\n // )\n // })\n // })\n\n // const observeDom = () => {\n // // Observe changes to the entire document\n // mutationObserver.observe(document, {\n // childList: true, // Detect added or removed child nodes\n // subtree: true, // Monitor all descendants\n // characterData: true, // Detect text content changes\n // })\n // }\n\n // const unobserveDom = () => {\n // mutationObserver.disconnect()\n // }\n\n // observeDom()\n\n const onScroll = (event: Event) => {\n // unobserveDom()\n\n if (ignoreScroll || !router.isScrollRestoring) {\n return\n }\n\n let elementSelector = ''\n\n if (event.target === document || event.target === window) {\n elementSelector = 'window'\n } else {\n const attrId = (event.target as Element).getAttribute(\n 'data-scroll-restoration-id',\n )\n\n if (attrId) {\n elementSelector = `[data-scroll-restoration-id=\"${attrId}\"]`\n } else {\n elementSelector = getCssSelector(event.target)\n }\n }\n\n const restoreKey = getKey(router.state.location)\n\n scrollRestorationCache.set((state) => {\n const keyEntry = (state[restoreKey] =\n state[restoreKey] || ({} as ScrollRestorationByElement))\n\n const elementEntry = (keyEntry[elementSelector] =\n keyEntry[elementSelector] || ({} as ScrollRestorationEntry))\n\n if (elementSelector === 'window') {\n elementEntry.scrollX = window.scrollX || 0\n elementEntry.scrollY = window.scrollY || 0\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n elementEntry.scrollX = element.scrollLeft || 0\n elementEntry.scrollY = element.scrollTop || 0\n }\n }\n\n return state\n })\n }\n\n // Throttle the scroll event to avoid excessive updates\n if (typeof document !== 'undefined') {\n document.addEventListener('scroll', throttle(onScroll, 100), true)\n }\n\n router.subscribe('onRendered', (event) => {\n // unobserveDom()\n\n const cacheKey = getKey(event.toLocation)\n\n // If the user doesn't want to restore the scroll position,\n // we don't need to do anything.\n if (!router.resetNextScroll) {\n router.resetNextScroll = true\n return\n }\n\n restoreScroll(\n storageKey,\n cacheKey,\n router.options.scrollRestorationBehavior,\n router.isScrollRestoring,\n router.options.scrollToTopSelectors,\n )\n\n if (router.isScrollRestoring) {\n // Mark the location as having been seen\n scrollRestorationCache.set((state) => {\n state[cacheKey] = state[cacheKey] || ({} as ScrollRestorationByElement)\n\n return state\n })\n }\n })\n}\n\nexport function ScrollRestoration() {\n const router = useRouter()\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n const userKey = getKey(router.latestLocation)\n const resolvedKey =\n userKey !== defaultGetScrollRestorationKey(router.latestLocation)\n ? userKey\n : null\n\n if (!router.isScrollRestoring || !router.isServer) {\n return null\n }\n\n return (\n <ScriptOnce\n children={`(${restoreScroll.toString()})(${JSON.stringify(storageKey)},${JSON.stringify(resolvedKey)}, undefined, true)`}\n log={false}\n />\n )\n}\n"],"names":["storageKey","sessionsStorage","window","sessionStorage","throttle","fn","wait","timeout","args","setTimeout","scrollRestorationCache","state","JSON","parse","getItem","set","updater","functionalUpdate","setItem","stringify","undefined","defaultGetScrollRestorationKey","location","key","href","getCssSelector","el","path","parent","parentNode","unshift","tagName","indexOf","call","children","join","toLowerCase","ignoreScroll","restoreScroll","behavior","shouldScrollRestoration","scrollToTopSelectors","byKey","error","console","resolvedKey","history","elementEntries","elementSelector","entry","scrollTo","top","scrollY","left","scrollX","element","document","querySelector","scrollLeft","scrollTop","hash","split","hashScrollIntoViewOptions","__hashScrollIntoViewOptions","getElementById","scrollIntoView","filter","d","forEach","selector","setupScrollRestoration","router","force","options","scrollRestoration","isScrollRestoring","isScrollRestorationSetup","getKey","getScrollRestorationKey","onScroll","event","target","attrId","getAttribute","restoreKey","keyEntry","elementEntry","addEventListener","subscribe","cacheKey","toLocation","resetNextScroll","scrollRestorationBehavior","ScrollRestoration","useRouter","userKey","latestLocation","isServer","_$createComponent","ScriptOnce","toString","log"],"mappings":";;;;AAyBO,MAAMA,aAAa;AAC1B,IAAIC,kBAAkB;AACtB,IAAI;AACFA,oBACE,OAAOC,WAAW,eAAe,OAAOA,OAAOC,mBAAmB;AACtE,QAAQ;AAAC;AACT,MAAMC,WAAWA,CAACC,IAAmCC,SAAiB;AAChEC,MAAAA;AACJ,SAAO,IAAIC,SAAqB;AAC9B,QAAI,CAACD,S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F,SAAS2E,UAAU,GAAG,GAAG,IAAI;AAAA,EAAA;AAG5DS,SAAAA,UAAU,cAAeR,CAAU,UAAA;AAGlCS,UAAAA,WAAWZ,OAAOG,MAAMU,UAAU;AAIpC,QAAA,CAACnB,OAAOoB,iBAAiB;AAC3BpB,aAAOoB,kBAAkB;AACzB;AAAA,IAAA;AAIA3F,kBAAAA,YACAyF,UACAlB,OAAOE,QAAQmB,2BACfrB,OAAOI,mBACPJ,OAAOE,QAAQhC,oBACjB;AAEA,QAAI8B,OAAOI,mBAAmB;AAE5BjE,6BAAuBK,IAAKJ,CAAU,UAAA;AACpCA,cAAM8E,QAAQ,IAAI9E,MAAM8E,QAAQ,KAAM,CAAC;AAEhC9E,eAAAA;AAAAA,MAAAA,CACR;AAAA,IAAA;AAAA,EACH,CACD;AACH;AAEO,SAASkF,oBAAoB;AAClC,QAAMtB,SAASuB,UAAU;AACnBjB,QAAAA,SACJN,OAAOE,QAAQK,2BAA2BzD;AACtC0E,QAAAA,UAAUlB,OAAON,OAAOyB,cAAc;AAC5C,QAAMnD,cACJkD,YAAY1E,+BAA+BkD,OAAOyB,cAAc,IAC5DD,UACA;AAEN,MAAI,CAACxB,OAAOI,qBAAqB,CAACJ,OAAO0B,UAAU;AAC1C,WAAA;AAAA,EAAA;AAGT,SAAAC,gBACGC,YAAU;AAAA,IAAA,IACTjE,WAAQ;AAAA,aAAE,IAAII,cAAc8D,SAAS,CAAC,KAAKxF,KAAKO,UAAUnB,UAAU,CAAC,IAAIY,KAAKO,UAAU0B,WAAW,CAAC;AAAA,IAAoB;AAAA,IACxHwD,KAAK;AAAA,EAAA,CAAK;AAGhB;"}
1
+ {"version":3,"file":"scroll-restoration.js","sources":["../../src/scroll-restoration.tsx"],"sourcesContent":["import { functionalUpdate } from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport { ScriptOnce } from './ScriptOnce'\n\nimport type {\n AnyRouter,\n NonNullableUpdater,\n ParsedLocation,\n} from '@tanstack/router-core'\n\nexport type ScrollRestorationEntry = { scrollX: number; scrollY: number }\n\nexport type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>\n\nexport type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>\n\nexport type ScrollRestorationCache = {\n state: ScrollRestorationByKey\n set: (updater: NonNullableUpdater<ScrollRestorationByKey>) => void\n}\nexport type ScrollRestorationOptions = {\n getKey?: (location: ParsedLocation) => string\n scrollBehavior?: ScrollToOptions['behavior']\n}\n\nexport const storageKey = 'tsr-scroll-restoration-v1_3'\nlet sessionsStorage = false\ntry {\n sessionsStorage =\n typeof window !== 'undefined' && typeof window.sessionStorage === 'object'\n} catch {}\nconst throttle = (fn: (...args: Array<any>) => void, wait: number) => {\n let timeout: any\n return (...args: Array<any>) => {\n if (!timeout) {\n timeout = setTimeout(() => {\n fn(...args)\n timeout = null\n }, wait)\n }\n }\n}\nexport const scrollRestorationCache: ScrollRestorationCache = sessionsStorage\n ? (() => {\n const state: ScrollRestorationByKey =\n JSON.parse(window.sessionStorage.getItem(storageKey) || 'null') || {}\n\n return {\n state,\n // This setter is simply to make sure that we set the sessionStorage right\n // after the state is updated. It doesn't necessarily need to be a functional\n // update.\n set: (updater) => (\n (scrollRestorationCache.state =\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n functionalUpdate(updater, scrollRestorationCache.state) ||\n scrollRestorationCache.state),\n window.sessionStorage.setItem(\n storageKey,\n JSON.stringify(scrollRestorationCache.state),\n )\n ),\n }\n })()\n : (undefined as any)\n/**\n * The default `getKey` function for `useScrollRestoration`.\n * It returns the `key` from the location state or the `href` of the location.\n *\n * The `location.href` is used as a fallback to support the use case where the location state is not available like the initial render.\n */\n\nexport const defaultGetScrollRestorationKey = (location: ParsedLocation) => {\n return location.state.key! || location.href\n}\n\nexport function getCssSelector(el: any): string {\n const path = []\n let parent\n while ((parent = el.parentNode)) {\n path.unshift(\n `${el.tagName}:nth-child(${([].indexOf as any).call(parent.children, el) + 1})`,\n )\n el = parent\n }\n return `${path.join(' > ')}`.toLowerCase()\n}\n\nlet ignoreScroll = false\n\n// NOTE: This function must remain pure and not use any outside variables\n// unless they are passed in as arguments. Why? Because we need to be able to\n// toString() it into a script tag to execute as early as possible in the browser\n// during SSR. Additionally, we also call it from within the router lifecycle\nexport function restoreScroll(\n storageKey: string,\n key: string | undefined,\n behavior: ScrollToOptions['behavior'] | undefined,\n shouldScrollRestoration: boolean | undefined,\n scrollToTopSelectors: Array<string> | undefined,\n) {\n let byKey: ScrollRestorationByKey\n\n try {\n byKey = JSON.parse(sessionStorage.getItem(storageKey) || '{}')\n } catch (error: any) {\n console.error(error)\n return\n }\n\n const resolvedKey = key || window.history.state?.key\n const elementEntries = byKey[resolvedKey]\n\n //\n ignoreScroll = true\n\n //\n ;(() => {\n // If we have a cached entry for this location state,\n // we always need to prefer that over the hash scroll.\n if (shouldScrollRestoration && elementEntries) {\n for (const elementSelector in elementEntries) {\n const entry = elementEntries[elementSelector]!\n if (elementSelector === 'window') {\n window.scrollTo({\n top: entry.scrollY,\n left: entry.scrollX,\n behavior,\n })\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n element.scrollLeft = entry.scrollX\n element.scrollTop = entry.scrollY\n }\n }\n }\n\n return\n }\n\n // If we don't have a cached entry for the hash,\n // Which means we've never seen this location before,\n // we need to check if there is a hash in the URL.\n // If there is, we need to scroll it's ID into view.\n const hash = window.location.hash.split('#')[1]\n\n if (hash) {\n const hashScrollIntoViewOptions =\n (window.history.state || {}).__hashScrollIntoViewOptions ?? true\n\n if (hashScrollIntoViewOptions) {\n const el = document.getElementById(hash)\n if (el) {\n el.scrollIntoView(hashScrollIntoViewOptions)\n }\n }\n\n return\n }\n\n // If there is no cached entry for the hash and there is no hash in the URL,\n // we need to scroll to the top of the page for every scrollToTop element\n ;[\n 'window',\n ...(scrollToTopSelectors?.filter((d) => d !== 'window') ?? []),\n ].forEach((selector) => {\n const element =\n selector === 'window' ? window : document.querySelector(selector)\n if (element) {\n element.scrollTo({\n top: 0,\n left: 0,\n behavior,\n })\n }\n })\n })()\n\n //\n ignoreScroll = false\n}\n\nexport function setupScrollRestoration(router: AnyRouter, force?: boolean) {\n const shouldScrollRestoration =\n force ?? router.options.scrollRestoration ?? false\n\n if (shouldScrollRestoration) {\n router.isScrollRestoring = true\n }\n\n if (typeof document === 'undefined' || router.isScrollRestorationSetup) {\n return\n }\n\n router.isScrollRestorationSetup = true\n\n //\n ignoreScroll = false\n\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n\n window.history.scrollRestoration = 'manual'\n\n // // Create a MutationObserver to monitor DOM changes\n // const mutationObserver = new MutationObserver(() => {\n // ;ignoreScroll = true\n // requestAnimationFrame(() => {\n // ;ignoreScroll = false\n\n // // Attempt to restore scroll position on each dom\n // // mutation until the user scrolls. We do this\n // // because dynamic content may come in at different\n // // ticks after the initial render and we want to\n // // keep up with that content as much as possible.\n // // As soon as the user scrolls, we no longer need\n // // to attempt router.\n // // console.log('mutation observer restoreScroll')\n // restoreScroll(\n // storageKey,\n // getKey(router.state.location),\n // router.options.scrollRestorationBehavior,\n // )\n // })\n // })\n\n // const observeDom = () => {\n // // Observe changes to the entire document\n // mutationObserver.observe(document, {\n // childList: true, // Detect added or removed child nodes\n // subtree: true, // Monitor all descendants\n // characterData: true, // Detect text content changes\n // })\n // }\n\n // const unobserveDom = () => {\n // mutationObserver.disconnect()\n // }\n\n // observeDom()\n\n const onScroll = (event: Event) => {\n // unobserveDom()\n\n if (ignoreScroll || !router.isScrollRestoring) {\n return\n }\n\n let elementSelector = ''\n\n if (event.target === document || event.target === window) {\n elementSelector = 'window'\n } else {\n const attrId = (event.target as Element).getAttribute(\n 'data-scroll-restoration-id',\n )\n\n if (attrId) {\n elementSelector = `[data-scroll-restoration-id=\"${attrId}\"]`\n } else {\n elementSelector = getCssSelector(event.target)\n }\n }\n\n const restoreKey = getKey(router.state.location)\n\n scrollRestorationCache.set((state) => {\n const keyEntry = (state[restoreKey] =\n state[restoreKey] || ({} as ScrollRestorationByElement))\n\n const elementEntry = (keyEntry[elementSelector] =\n keyEntry[elementSelector] || ({} as ScrollRestorationEntry))\n\n if (elementSelector === 'window') {\n elementEntry.scrollX = window.scrollX || 0\n elementEntry.scrollY = window.scrollY || 0\n } else if (elementSelector) {\n const element = document.querySelector(elementSelector)\n if (element) {\n elementEntry.scrollX = element.scrollLeft || 0\n elementEntry.scrollY = element.scrollTop || 0\n }\n }\n\n return state\n })\n }\n\n // Throttle the scroll event to avoid excessive updates\n if (typeof document !== 'undefined') {\n document.addEventListener('scroll', throttle(onScroll, 100), true)\n }\n\n router.subscribe('onRendered', (event) => {\n // unobserveDom()\n\n const cacheKey = getKey(event.toLocation)\n\n // If the user doesn't want to restore the scroll position,\n // we don't need to do anything.\n if (!router.resetNextScroll) {\n router.resetNextScroll = true\n return\n }\n\n restoreScroll(\n storageKey,\n cacheKey,\n router.options.scrollRestorationBehavior || undefined,\n router.isScrollRestoring || undefined,\n router.options.scrollToTopSelectors || undefined,\n )\n\n if (router.isScrollRestoring) {\n // Mark the location as having been seen\n scrollRestorationCache.set((state) => {\n state[cacheKey] = state[cacheKey] || ({} as ScrollRestorationByElement)\n\n return state\n })\n }\n })\n}\n\nexport function ScrollRestoration() {\n const router = useRouter()\n const getKey =\n router.options.getScrollRestorationKey || defaultGetScrollRestorationKey\n const userKey = getKey(router.latestLocation)\n const resolvedKey =\n userKey !== defaultGetScrollRestorationKey(router.latestLocation)\n ? userKey\n : null\n\n if (!router.isScrollRestoring || !router.isServer) {\n return null\n }\n\n return (\n <ScriptOnce\n children={`(${restoreScroll.toString()})(${JSON.stringify(storageKey)},${JSON.stringify(resolvedKey)}, undefined, true)`}\n log={false}\n />\n )\n}\n"],"names":["storageKey","sessionsStorage","window","sessionStorage","throttle","fn","wait","timeout","args","setTimeout","scrollRestorationCache","state","JSON","parse","getItem","set","updater","functionalUpdate","setItem","stringify","undefined","defaultGetScrollRestorationKey","location","key","href","getCssSelector","el","path","parent","parentNode","unshift","tagName","indexOf","call","children","join","toLowerCase","ignoreScroll","restoreScroll","behavior","shouldScrollRestoration","scrollToTopSelectors","byKey","error","console","resolvedKey","history","elementEntries","elementSelector","entry","scrollTo","top","scrollY","left","scrollX","element","document","querySelector","scrollLeft","scrollTop","hash","split","hashScrollIntoViewOptions","__hashScrollIntoViewOptions","getElementById","scrollIntoView","filter","d","forEach","selector","setupScrollRestoration","router","force","options","scrollRestoration","isScrollRestoring","isScrollRestorationSetup","getKey","getScrollRestorationKey","onScroll","event","target","attrId","getAttribute","restoreKey","keyEntry","elementEntry","addEventListener","subscribe","cacheKey","toLocation","resetNextScroll","scrollRestorationBehavior","ScrollRestoration","useRouter","userKey","latestLocation","isServer","_$createComponent","ScriptOnce","toString","log"],"mappings":";;;;AAyBO,MAAMA,aAAa;AAC1B,IAAIC,kBAAkB;AACtB,IAAI;AACFA,oBACE,OAAOC,WAAW,eAAe,OAAOA,OAAOC,mBAAmB;AACtE,QAAQ;AAAC;AACT,MAAMC,WAAWA,CAACC,IAAmCC,SAAiB;AAChEC,MAAAA;AACJ,SAAO,IAAIC,SAAqB;AAC9B,QAAI,CAACD,SAAS;AACZA,gBAAUE,WAAW,MAAM;AACzBJ,WAAG,GAAGG,IAAI;AACA,kBAAA;AAAA,SACTF,IAAI;AAAA,IAAA;AAAA,EAEX;AACF;AACaI,MAAAA,yBAAiDT,mBACzD,MAAM;AACCU,QAAAA,QACJC,KAAKC,MAAMX,OAAOC,eAAeW,QAAQd,UAAU,KAAK,MAAM,KAAK,CAAC;AAE/D,SAAA;AAAA,IACLW;AAAAA;AAAAA;AAAAA;AAAAA,IAIAI,KAAMC,cACHN,uBAAuBC;AAAAA,IAEtBM,iBAAiBD,SAASN,uBAAuBC,KAAK,KACtDD,uBAAuBC,OACzBT,OAAOC,eAAee,QACpBlB,YACAY,KAAKO,UAAUT,uBAAuBC,KAAK,CAC7C;AAAA,EAEJ;AACF,OACCS;AAQQC,MAAAA,iCAAiCA,CAACC,aAA6B;AACn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EACH,CACD;AACH;AAEO,SAASkF,oBAAoB;AAClC,QAAMtB,SAASuB,UAAU;AACnBjB,QAAAA,SACJN,OAAOE,QAAQK,2BAA2BzD;AACtC0E,QAAAA,UAAUlB,OAAON,OAAOyB,cAAc;AAC5C,QAAMnD,cACJkD,YAAY1E,+BAA+BkD,OAAOyB,cAAc,IAC5DD,UACA;AAEN,MAAI,CAACxB,OAAOI,qBAAqB,CAACJ,OAAO0B,UAAU;AAC1C,WAAA;AAAA,EAAA;AAGT,SAAAC,gBACGC,YAAU;AAAA,IAAA,IACTjE,WAAQ;AAAA,aAAE,IAAII,cAAc8D,SAAS,CAAC,KAAKxF,KAAKO,UAAUnB,UAAU,CAAC,IAAIY,KAAKO,UAAU0B,WAAW,CAAC;AAAA,IAAoB;AAAA,IACxHwD,KAAK;AAAA,EAAA,CAAK;AAGhB;"}
@@ -23,6 +23,6 @@ export declare const scrollRestorationCache: ScrollRestorationCache;
23
23
  */
24
24
  export declare const defaultGetScrollRestorationKey: (location: ParsedLocation) => string;
25
25
  export declare function getCssSelector(el: any): string;
26
- export declare function restoreScroll(storageKey: string, key?: string, behavior?: ScrollToOptions['behavior'], shouldScrollRestoration?: boolean, scrollToTopSelectors?: Array<string>): void;
26
+ export declare function restoreScroll(storageKey: string, key: string | undefined, behavior: ScrollToOptions['behavior'] | undefined, shouldScrollRestoration: boolean | undefined, scrollToTopSelectors: Array<string> | undefined): void;
27
27
  export declare function setupScrollRestoration(router: AnyRouter, force?: boolean): void;
28
28
  export declare function ScrollRestoration(): import("solid-js").JSX.Element;
@@ -28,6 +28,7 @@ export const scrollRestorationCache = sessionsStorage
28
28
  // after the state is updated. It doesn't necessarily need to be a functional
29
29
  // update.
30
30
  set: (updater) => ((scrollRestorationCache.state =
31
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
31
32
  functionalUpdate(updater, scrollRestorationCache.state) ||
32
33
  scrollRestorationCache.state),
33
34
  window.sessionStorage.setItem(storageKey, JSON.stringify(scrollRestorationCache.state))),
@@ -224,7 +225,7 @@ export function setupScrollRestoration(router, force) {
224
225
  router.resetNextScroll = true;
225
226
  return;
226
227
  }
227
- restoreScroll(storageKey, cacheKey, router.options.scrollRestorationBehavior, router.isScrollRestoring, router.options.scrollToTopSelectors);
228
+ restoreScroll(storageKey, cacheKey, router.options.scrollRestorationBehavior || undefined, router.isScrollRestoring || undefined, router.options.scrollToTopSelectors || undefined);
228
229
  if (router.isScrollRestoring) {
229
230
  // Mark the location as having been seen
230
231
  scrollRestorationCache.set((state) => {
@@ -1 +1 @@
1
- {"version":3,"file":"scroll-restoration.jsx","sourceRoot":"","sources":["../../src/scroll-restoration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAuBzC,MAAM,CAAC,MAAM,UAAU,GAAG,6BAA6B,CAAA;AACvD,IAAI,eAAe,GAAG,KAAK,CAAA;AAC3B,IAAI,CAAC;IACH,eAAe;QACb,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,cAAc,KAAK,QAAQ,CAAA;AAC9E,CAAC;AAAC,MAAM,CAAC,CAAA,CAAC;AACV,MAAM,QAAQ,GAAG,CAAC,EAAiC,EAAE,IAAY,EAAE,EAAE;IACnE,IAAI,OAAY,CAAA;IAChB,OAAO,CAAC,GAAG,IAAgB,EAAE,EAAE;QAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBACxB,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;gBACX,OAAO,GAAG,IAAI,CAAA;YAChB,CAAC,EAAE,IAAI,CAAC,CAAA;QACV,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,sBAAsB,GAA2B,eAAe;IAC3E,CAA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,GACV,MAAM,CAAC,OAAO,CAAC,uBAAuB,IAAI,8BAA8B,CAAA;IAC1E,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;IAC7C,MAAM,WAAW,GACf,OAAO,KAAK,8BAA8B,CAAC,MAAM,CAAC,cAAc,CAAC;QAC/D,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,IAAI,CAAA;IAEV,IAAI,CAAC,MAAM,CAAC,iBAAiB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,CACL,CAAC,UAAU,CACT,QAAQ,CAAC,CAAC,IAAI,aAAa,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,oBAAoB,CAAC,CACzH,GAAG,CAAC,CAAC,KAAK,CAAC,EACX,CACH,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-router",
3
- "version": "1.114.1",
3
+ "version": "1.114.3",
4
4
  "description": "Modern and scalable routing for Solid applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -60,8 +60,8 @@
60
60
  "jsesc": "^3.0.2",
61
61
  "tiny-invariant": "^1.3.3",
62
62
  "tiny-warning": "^1.0.3",
63
- "@tanstack/history": "1.114.1",
64
- "@tanstack/router-core": "1.114.1"
63
+ "@tanstack/router-core": "1.114.3",
64
+ "@tanstack/history": "1.114.3"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@solidjs/testing-library": "^0.8.10",
@@ -52,6 +52,7 @@ export const scrollRestorationCache: ScrollRestorationCache = sessionsStorage
52
52
  // update.
53
53
  set: (updater) => (
54
54
  (scrollRestorationCache.state =
55
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
55
56
  functionalUpdate(updater, scrollRestorationCache.state) ||
56
57
  scrollRestorationCache.state),
57
58
  window.sessionStorage.setItem(
@@ -93,10 +94,10 @@ let ignoreScroll = false
93
94
  // during SSR. Additionally, we also call it from within the router lifecycle
94
95
  export function restoreScroll(
95
96
  storageKey: string,
96
- key?: string,
97
- behavior?: ScrollToOptions['behavior'],
98
- shouldScrollRestoration?: boolean,
99
- scrollToTopSelectors?: Array<string>,
97
+ key: string | undefined,
98
+ behavior: ScrollToOptions['behavior'] | undefined,
99
+ shouldScrollRestoration: boolean | undefined,
100
+ scrollToTopSelectors: Array<string> | undefined,
100
101
  ) {
101
102
  let byKey: ScrollRestorationByKey
102
103
 
@@ -306,9 +307,9 @@ export function setupScrollRestoration(router: AnyRouter, force?: boolean) {
306
307
  restoreScroll(
307
308
  storageKey,
308
309
  cacheKey,
309
- router.options.scrollRestorationBehavior,
310
- router.isScrollRestoring,
311
- router.options.scrollToTopSelectors,
310
+ router.options.scrollRestorationBehavior || undefined,
311
+ router.isScrollRestoring || undefined,
312
+ router.options.scrollToTopSelectors || undefined,
312
313
  )
313
314
 
314
315
  if (router.isScrollRestoring) {