Skip to content

Commit

Permalink
Hacky fix to unwanted scroll preservation, should do something nicer …
Browse files Browse the repository at this point in the history
…later

The issue is the Layout component div being 100vh, which means the default scroll to top doesn't work. Need to find a way to get around that without breaking everything.
  • Loading branch information
futurGH committed Jul 21, 2023
1 parent c1df6bf commit ec0ad69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/App.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import {
import renderHydrogen from "@shopify/hydrogen/entry-server";
import { Suspense } from "react";
import { NotFound } from "./components/global/NotFound.server";
import { ScrollReset } from "./lib/ScrollReset.client";

function App() {
return (
<Suspense fallback={null}>
<ScrollReset />
<ShopifyProvider>
<ShopifyAnalytics cookieDomain="teacaps.studio" />
<CartProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/components/global/CustomSeo.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function CustomSeo(props: CustomSeoProps) {
preload: "*",
});

console.log(errors);
if (errors) console.log(errors);

const url = useUrl();
const image = props.image?.includes("://") ? props.image : url.origin + (props.image || "/landing-og-image.png");
Expand Down
8 changes: 8 additions & 0 deletions src/lib/ScrollReset.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useLayoutEffect } from "react";

export function ScrollReset() {
useLayoutEffect(() => {
document.querySelector("#root > div")?.scrollTo({ top: 0, behavior: "smooth" });
});
return null;
}

0 comments on commit ec0ad69

Please sign in to comment.