Disables batching for i18n query (#3181)

* Disables batching for i18n query

* Makes i18n batch skip explicit
This commit is contained in:
Omar López
2022-07-18 12:59:51 -06:00
committed by GitHub
parent ef36a93a55
commit df3e3e8237
4 changed files with 16 additions and 5 deletions
@@ -6,6 +6,11 @@ import { trpc } from "@lib/trpc";
export function useViewerI18n() {
return trpc.useQuery(["viewer.public.i18n"], {
staleTime: Infinity,
/**
* i18n should never be clubbed with other queries, so that it's caching can be managed independently.
* We intend to not cache i18n query
**/
context: { skipBatch: true },
});
}
+5 -1
View File
@@ -26,7 +26,11 @@ type AppPropsWithChildren = AppProps & {
};
const CustomI18nextProvider = (props: AppPropsWithChildren) => {
const { i18n, locale } = trpc.useQuery(["viewer.public.i18n"]).data ?? {
/**
* i18n should never be clubbed with other queries, so that it's caching can be managed independently.
* We intend to not cache i18n query
**/
const { i18n, locale } = trpc.useQuery(["viewer.public.i18n"], { context: { skipBatch: true } }).data ?? {
locale: "en",
};
+1 -3
View File
@@ -85,9 +85,7 @@ export default withTRPC<AppRouter>({
splitLink({
// check for context property `skipBatch`
condition: (op) => {
// i18n should never be clubbed with other queries, so that it's caching can be managed independently
// We intend to not cache i18n query
return op.context.skipBatch === true || op.path === "viewer.public.i18n";
return op.context.skipBatch === true;
},
// when condition is true, use normal request
true: httpLink({ url }),
+5 -1
View File
@@ -501,7 +501,11 @@ function SettingsView(props: ComponentProps<typeof Settings> & { localeProp: str
);
}
const WithQuery = withQuery(["viewer.public.i18n"]);
/**
* i18n should never be clubbed with other queries, so that it's caching can be managed independently.
* We intend to not cache i18n query
**/
const WithQuery = withQuery(["viewer.public.i18n"], { context: { skipBatch: true } });
export default function Settings(props: Props) {
const { t } = useLocale();