From 453ec6b12f8c021e0bd0fd0ea9f71c8fc280f4b1 Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:09:05 +0100 Subject: [PATCH] prevents access to the history state if not set (#12436) --- .changeset/dirty-teachers-know.md | 5 +++++ packages/astro/src/transitions/router.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/dirty-teachers-know.md diff --git a/.changeset/dirty-teachers-know.md b/.changeset/dirty-teachers-know.md new file mode 100644 index 000000000000..951117ffff1a --- /dev/null +++ b/.changeset/dirty-teachers-know.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a potential null access in the clientside router diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index 2be12895e53f..cb5476a7a588 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -636,7 +636,7 @@ if (inBrowser) { 'scroll', () => { if (intervalId !== undefined) return; - (lastIndex = history.state.index), (lastY = scrollY), (lastX = scrollX); + (lastIndex = history.state?.index), (lastY = scrollY), (lastX = scrollX); intervalId = window.setInterval(scrollInterval, 50); }, { passive: true },