Replies: 1 comment
-
I agree that this should be reconsidered. Another thing this does is mess with the types that are returned in the component. With the following code, the standard export async function loader(_: Route.LoaderArgs) {
return { foo: "bar" };
}
export async function clientLoader({
request,
serverLoader,
}: Route.ClientLoaderArgs) {
return await setTimeout(500, serverLoader, { signal: request.signal });
}
export default function Page({ loaderData }: Route.ComponentProps) {
return <div></div>;
} Hovering over the loaderData: {
foo: string;
} | (() => Promise<{
foo: string;
}>) Now, changing this back to calling the server loader directly: export async function clientLoader({ serverLoader }: Route.ClientLoaderArgs) {
return await serverLoader();
} It now results in the correct following derived type in the component: loaderData: {
foo: string;
} Now, the best way to actually go about this would be to do things more manually with a raw export async function clientLoader({
request,
serverLoader,
}: Route.ClientLoaderArgs) {
return new Promise(
(resolve: (value: Awaited<ReturnType<typeof serverLoader>>) => void) => {
const fn = async () => {
resolve(await serverLoader());
};
setTimeout(fn, 300, { signal: request.signal });
}
);
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I noticed that
useDebounceFetcher
anduseDebounceSubmit
will be deprecated in the next version in favor of debouncing at the clientLoader level, which I agree is probably a better approach most of the times.However, how does the provided example work?
We're importing and using node stuff,
setTimeout
fromnode:timers
, inside a client only loader. To my understanding, this is not possible right?Beta Was this translation helpful? Give feedback.
All reactions