From 70c8e2bc4bf0b9fb03ea21870cbafdd7adac22eb Mon Sep 17 00:00:00 2001 From: yjl9903 Date: Thu, 3 Oct 2024 21:36:15 +0800 Subject: [PATCH] fix(web): pass after scroll callback --- patches/@remix-run__react.patch | 16 ++++++++++------ pnpm-lock.yaml | 12 ++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/patches/@remix-run__react.patch b/patches/@remix-run__react.patch index 1e09a740..52ef8248 100644 --- a/patches/@remix-run__react.patch +++ b/patches/@remix-run__react.patch @@ -9,7 +9,7 @@ index fbfe1d149da86ecb95341e9a00443b395b875d05..826cabf5a217db7f2d75b72142194217 + afterScroll?: (x: number, y: number) => void; }): React.JSX.Element | null; diff --git a/dist/scroll-restoration.js b/dist/scroll-restoration.js -index b7aa82aeabc7de43007c66c2a15e23c1026ace7e..005593ae155709c1679cae844851cc8c340778d9 100644 +index b7aa82aeabc7de43007c66c2a15e23c1026ace7e..e8b68ab4b009233bf16432cfdb7655eebf680ef4 100644 --- a/dist/scroll-restoration.js +++ b/dist/scroll-restoration.js @@ -47,6 +47,7 @@ let STORAGE_KEY = "positions"; @@ -20,17 +20,21 @@ index b7aa82aeabc7de43007c66c2a15e23c1026ace7e..005593ae155709c1679cae844851cc8c ...props }) { let { -@@ -79,6 +80,9 @@ function ScrollRestoration({ +@@ -79,6 +80,13 @@ function ScrollRestoration({ if (isSpaMode) { return null; } -+ if (!import.meta.env.SSR) { -+ window.__afterScroll__ = afterScroll; -+ } ++ ++ React__namespace.useEffect(() => { ++ if (window) { ++ window.__afterScroll__ = afterScroll; ++ } ++ }); ++ let restoreScroll = ((STORAGE_KEY, restoreKey) => { if (!window.history.state || !window.history.state.key) { let key = Math.random().toString(32).slice(2); -@@ -91,6 +95,7 @@ function ScrollRestoration({ +@@ -91,6 +99,7 @@ function ScrollRestoration({ let storedY = positions[restoreKey || window.history.state.key]; if (typeof storedY === "number") { window.scrollTo(0, storedY); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 014fed75..26125c82 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,7 +6,7 @@ settings: patchedDependencies: '@remix-run/react': - hash: byqxw5ezivyl44qnwucuz5vzxi + hash: bjemw5nwrqtcsikt2rpurjknri path: patches/@remix-run__react.patch importers: @@ -90,7 +90,7 @@ importers: version: 2.12.0(typescript@5.6.2) '@remix-run/react': specifier: ^2.12.0 - version: 2.12.0(patch_hash=byqxw5ezivyl44qnwucuz5vzxi)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2) + version: 2.12.0(patch_hash=bjemw5nwrqtcsikt2rpurjknri)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2) '@remix-run/serve': specifier: ^2.12.0 version: 2.12.0(typescript@5.6.2) @@ -160,7 +160,7 @@ importers: version: 1.2.0 '@remix-run/dev': specifier: ^2.12.0 - version: 2.12.0(@remix-run/react@2.12.0(patch_hash=byqxw5ezivyl44qnwucuz5vzxi)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2))(@remix-run/serve@2.12.0(typescript@5.6.2))(@types/node@20.16.5)(bufferutil@4.0.8)(terser@5.31.6)(typescript@5.6.2)(utf-8-validate@6.0.4)(vite@5.4.2(@types/node@20.16.5)(terser@5.31.6))(wrangler@3.78.2(@cloudflare/workers-types@4.20240909.0)(bufferutil@4.0.8)(utf-8-validate@6.0.4)) + version: 2.12.0(@remix-run/react@2.12.0(patch_hash=bjemw5nwrqtcsikt2rpurjknri)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2))(@remix-run/serve@2.12.0(typescript@5.6.2))(@types/node@20.16.5)(bufferutil@4.0.8)(terser@5.31.6)(typescript@5.6.2)(utf-8-validate@6.0.4)(vite@5.4.2(@types/node@20.16.5)(terser@5.31.6))(wrangler@3.78.2(@cloudflare/workers-types@4.20240909.0)(bufferutil@4.0.8)(utf-8-validate@6.0.4)) '@types/react': specifier: ^18.3.5 version: 18.3.5 @@ -11797,7 +11797,7 @@ snapshots: optionalDependencies: typescript: 5.6.2 - '@remix-run/dev@2.12.0(@remix-run/react@2.12.0(patch_hash=byqxw5ezivyl44qnwucuz5vzxi)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2))(@remix-run/serve@2.12.0(typescript@5.6.2))(@types/node@20.16.5)(bufferutil@4.0.8)(terser@5.31.6)(typescript@5.6.2)(utf-8-validate@6.0.4)(vite@5.4.2(@types/node@20.16.5)(terser@5.31.6))(wrangler@3.78.2(@cloudflare/workers-types@4.20240909.0)(bufferutil@4.0.8)(utf-8-validate@6.0.4))': + '@remix-run/dev@2.12.0(@remix-run/react@2.12.0(patch_hash=bjemw5nwrqtcsikt2rpurjknri)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2))(@remix-run/serve@2.12.0(typescript@5.6.2))(@types/node@20.16.5)(bufferutil@4.0.8)(terser@5.31.6)(typescript@5.6.2)(utf-8-validate@6.0.4)(vite@5.4.2(@types/node@20.16.5)(terser@5.31.6))(wrangler@3.78.2(@cloudflare/workers-types@4.20240909.0)(bufferutil@4.0.8)(utf-8-validate@6.0.4))': dependencies: '@babel/core': 7.25.2 '@babel/generator': 7.25.6 @@ -11810,7 +11810,7 @@ snapshots: '@mdx-js/mdx': 2.3.0 '@npmcli/package-json': 4.0.1 '@remix-run/node': 2.12.0(typescript@5.6.2) - '@remix-run/react': 2.12.0(patch_hash=byqxw5ezivyl44qnwucuz5vzxi)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2) + '@remix-run/react': 2.12.0(patch_hash=bjemw5nwrqtcsikt2rpurjknri)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2) '@remix-run/router': 1.19.2 '@remix-run/server-runtime': 2.12.0(typescript@5.6.2) '@types/mdx': 2.0.13 @@ -11893,7 +11893,7 @@ snapshots: optionalDependencies: typescript: 5.6.2 - '@remix-run/react@2.12.0(patch_hash=byqxw5ezivyl44qnwucuz5vzxi)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2)': + '@remix-run/react@2.12.0(patch_hash=bjemw5nwrqtcsikt2rpurjknri)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.2)': dependencies: '@remix-run/router': 1.19.2 '@remix-run/server-runtime': 2.12.0(typescript@5.6.2)