Skip to content

Commit

Permalink
protip: don't reload root unless there's a POST
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanflorence committed Jan 11, 2022
1 parent 96f18e5 commit 457c75d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/containers/layout/layout.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useLoaderData,
useMatches,
} from "remix";
import type { MetaFunction } from "remix";
import type { MetaFunction, ShouldReloadFunction } from "remix";

import { ClientOnly } from "~/components/client-only";
import { Footer } from "~/components/footer";
Expand Down Expand Up @@ -194,6 +194,10 @@ export function ErrorBoundary({ error }: { error: Error }) {
);
}

export let unstable_shouldReload: ShouldReloadFunction = ({ submission }) => {
return submission?.method.toLowerCase() === "post";
};

export default function Root() {
let loaderData = useLoaderData<LoaderData>();

Expand Down
10 changes: 9 additions & 1 deletion app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import Component, {
CatchBoundary,
links,
meta,
unstable_shouldReload,
} from "~/containers/layout/layout.component";
import { loader } from "~/containers/layout/layout.server";

export default Component;
export { ErrorBoundary, CatchBoundary, loader, links, meta };
export {
ErrorBoundary,
CatchBoundary,
loader,
links,
meta,
unstable_shouldReload,
};

0 comments on commit 457c75d

Please sign in to comment.