mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 07:37:55 -05:00
16
app/components/ConditionalScrollRestoration.tsx
Normal file
16
app/components/ConditionalScrollRestoration.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
// temporary workaround before Remix has React Router 6.4
|
||||
// https://github.com/remix-run/remix/issues/186#issuecomment-1178395835
|
||||
|
||||
import { ScrollRestoration, useLocation } from "@remix-run/react";
|
||||
|
||||
export function ConditionalScrollRestoration() {
|
||||
const location = useLocation();
|
||||
if (
|
||||
location.state != null &&
|
||||
typeof location.state === "object" &&
|
||||
(location.state as { scroll: boolean }).scroll === false
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return <ScrollRestoration />;
|
||||
}
|
||||
@@ -40,12 +40,15 @@ export function useAnalyzeBuild() {
|
||||
newLdeIntensity?: number;
|
||||
newEffects?: Array<SpecialEffectType>;
|
||||
}) => {
|
||||
setSearchParams({
|
||||
weapon: String(newMainWeaponId),
|
||||
build: serializeBuild(newBuild),
|
||||
lde: String(newLdeIntensity),
|
||||
effect: newEffects,
|
||||
});
|
||||
setSearchParams(
|
||||
{
|
||||
weapon: String(newMainWeaponId),
|
||||
build: serializeBuild(newBuild),
|
||||
lde: String(newLdeIntensity),
|
||||
effect: newEffects,
|
||||
},
|
||||
{ replace: true, state: { scroll: false } }
|
||||
);
|
||||
};
|
||||
|
||||
const buildsAbilityPoints = buildToAbilityPoints(build);
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
Meta,
|
||||
Outlet,
|
||||
Scripts,
|
||||
ScrollRestoration,
|
||||
useLoaderData,
|
||||
type ShouldReloadFunction,
|
||||
} from "@remix-run/react";
|
||||
@@ -32,6 +31,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { Theme, ThemeHead, useTheme, ThemeProvider } from "./modules/theme";
|
||||
import { getThemeSession } from "./modules/theme/session.server";
|
||||
import { COMMON_PREVIEW_IMAGE } from "./utils/urls";
|
||||
import { ConditionalScrollRestoration } from "./components/ConditionalScrollRestoration";
|
||||
|
||||
export const unstable_shouldReload: ShouldReloadFunction = () => false;
|
||||
|
||||
@@ -112,7 +112,7 @@ function Document({
|
||||
{children}
|
||||
</Layout>
|
||||
</React.StrictMode>
|
||||
<ScrollRestoration />
|
||||
<ConditionalScrollRestoration />
|
||||
<Scripts />
|
||||
<LiveReload />
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user