From 96471cc47f0205d030b700724db7bb886d8d8227 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Tue, 26 Jul 2022 20:39:08 +0300 Subject: [PATCH] Optimize suggestions loader call amounts --- app/routes/plus/suggestions.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/routes/plus/suggestions.tsx b/app/routes/plus/suggestions.tsx index 7db9879e3..94636855a 100644 --- a/app/routes/plus/suggestions.tsx +++ b/app/routes/plus/suggestions.tsx @@ -4,7 +4,13 @@ import type { MetaFunction, } from "@remix-run/node"; import { json } from "@remix-run/node"; -import { Link, Outlet, useLoaderData, useSearchParams } from "@remix-run/react"; +import { + Link, + Outlet, + ShouldReloadFunction, + useLoaderData, + useSearchParams, +} from "@remix-run/react"; import clsx from "clsx"; import invariant from "tiny-invariant"; import { z } from "zod"; @@ -114,6 +120,11 @@ export interface PlusSuggestionsLoaderData { suggestedForTiers: number[]; } +export const unstable_shouldReload: ShouldReloadFunction = ({ submission }) => { + // only reload if form submission not when user changes tabs + return Boolean(submission); +}; + export const loader: LoaderFunction = async ({ request }) => { const user = await getUser(request);