perf: server-fetch data for all pages in /settings/my-account (#20712)
* wip * fix type check * refactor "/settings/my-account/profile" * refactor "settings/my-account/general" * refactor "/settings/my-accouunt/calendars" * refactor "/settings/my-account/appearance" * fix: type-check --------- Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com> Co-authored-by: Amit Sharma <samit91848@gmail.com>
This commit is contained in:
co-authored by
Amit Sharma
Amit Sharma
parent
6259b0b3cb
commit
6b9115dfde
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* This implementation is adapted from https://github.com/vercel/next.js/issues/51613#issuecomment-1892644565.
|
||||
* It is a wrapper around `unstable_cache` that adds serialization and deserialization
|
||||
*/
|
||||
import { unstable_cache } from "next/cache";
|
||||
import { parse, stringify } from "superjson";
|
||||
|
||||
export const cache = <T, P extends unknown[]>(
|
||||
fn: (...params: P) => Promise<T>,
|
||||
keys: Parameters<typeof unstable_cache>[1],
|
||||
opts: Parameters<typeof unstable_cache>[2]
|
||||
) => {
|
||||
const wrap = async (params: unknown[]): Promise<string> => {
|
||||
const result = await fn(...(params as P));
|
||||
return stringify(result);
|
||||
};
|
||||
|
||||
const cachedFn = unstable_cache(wrap, keys, opts);
|
||||
|
||||
return async (...params: P): Promise<T> => {
|
||||
const result = await cachedFn(params);
|
||||
return parse(result);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user