From 628a29e89c48915e4922d9cbb56521b0d93dd89a Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Wed, 19 Jul 2023 10:19:53 +0100 Subject: [PATCH] chore: fixing some initial re-renders (#10185) Co-authored-by: Keith Williams --- apps/web/components/I18nLanguageHandler.tsx | 9 +- apps/web/components/PageWrapper.tsx | 4 +- .../eventtype/EventAvailabilityTab.tsx | 159 +++++++++--------- apps/web/lib/app-providers.tsx | 17 +- .../insights/filters/EventTypeList.tsx | 8 +- packages/features/shell/Shell.tsx | 30 ++-- packages/features/tips/Tips.tsx | 9 +- packages/lib/hooks/useTraceUpdate.tsx | 21 +++ 8 files changed, 144 insertions(+), 113 deletions(-) create mode 100644 packages/lib/hooks/useTraceUpdate.tsx diff --git a/apps/web/components/I18nLanguageHandler.tsx b/apps/web/components/I18nLanguageHandler.tsx index f7c9ba2930..8297f529de 100644 --- a/apps/web/components/I18nLanguageHandler.tsx +++ b/apps/web/components/I18nLanguageHandler.tsx @@ -1,4 +1,3 @@ -import { isEmpty } from "lodash"; import { useTranslation } from "next-i18next"; import { useEffect } from "react"; @@ -20,13 +19,13 @@ export function useViewerI18n() { /** * Auto-switches locale client-side to the logged in user's preference */ -const I18nLanguageHandler = (): null => { +const useI18nLanguageHandler = () => { const { i18n } = useTranslation("common"); const locale = useViewerI18n().data?.locale || i18n.language; useEffect(() => { // bail early when i18n = {} - if (isEmpty(i18n)) return; + if (Object.keys(i18n).length === 0) return; // if locale is ready and the i18n.language does != locale - changeLanguage if (locale && i18n.language !== locale) { i18n.changeLanguage(locale); @@ -35,8 +34,6 @@ const I18nLanguageHandler = (): null => { document.dir = i18n.dir(); document.documentElement.setAttribute("lang", locale); }, [locale, i18n]); - - return null; }; -export default I18nLanguageHandler; +export default useI18nLanguageHandler; diff --git a/apps/web/components/PageWrapper.tsx b/apps/web/components/PageWrapper.tsx index c076ebd2da..b975cdafe7 100644 --- a/apps/web/components/PageWrapper.tsx +++ b/apps/web/components/PageWrapper.tsx @@ -13,7 +13,7 @@ import type { AppProps } from "@lib/app-providers"; import AppProviders from "@lib/app-providers"; import { seoConfig } from "@lib/config/next-seo.config"; -import I18nLanguageHandler from "@components/I18nLanguageHandler"; +import useI18nLanguageHandler from "@components/I18nLanguageHandler"; export interface CalPageWrapper { (props?: AppProps): JSX.Element; @@ -29,6 +29,7 @@ const calFont = localFont({ }); function PageWrapper(props: AppProps) { + useI18nLanguageHandler(); const { Component, pageProps, err, router } = props; let pageStatus = "200"; @@ -72,7 +73,6 @@ function PageWrapper(props: AppProps) { } {...seoConfig.defaultNextSeo} /> -