Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Lazy load SitewideBanner #10897

Closed
2 tasks
esizer opened this issue Jul 5, 2024 · 0 comments · Fixed by #10899
Closed
2 tasks

♻️ Lazy load SitewideBanner #10897

esizer opened this issue Jul 5, 2024 · 0 comments · Fixed by #10899
Assignees
Labels
debt Refactor or improve existing code.

Comments

@esizer
Copy link
Member

esizer commented Jul 5, 2024

♻️ Debt/Refactor

We should probably lazy load the component only if the query returns something we can render.

🕵️ Details

Currently, we always load the SitewideBanner component. The issue is, it contains a very heavy library (tiptap ~200kb) that we load, regardless if we ever intend to use it. We should lazy load this component only if it contains data we can render.

🙋‍♀️ Proposed Solution

I'm not 100% confident but this this could work? 🤔

// BannerContent.tsx
const BannerContent = ({ data }) => ();

// SitewideBanner.tsx
const Content = React.lazy(() => import("./BannerContent.tsx");

const SitewideBanner = () => {
  const [{data, fetching}] = useQuery({ .. });
  
  if(!data || fetching) return null;
  
  return (
     <Suspense fallback={<Loading />}
        <Content />
     </Suspense>
  );
}

✅ Acceptance Criteria

  • Tiptap lazy loaded only when needed
  • Sitewide banner can still render rich text
@esizer esizer added the debt Refactor or improve existing code. label Jul 5, 2024
@esizer esizer self-assigned this Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Refactor or improve existing code.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant