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

[docs-infra] Fix Banner CLS #44632

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/src/components/banner/AppFrameBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ function isBlackFriday() {
return today > start && today < end;
}

let hadHydrated = false;

export default function AppFrameBanner() {
if (!FEATURE_TOGGLE.enable_docsnav_banner) {
return null;
}

// eslint-disable-next-line react-hooks/rules-of-hooks
const [mounted, setMounted] = React.useState(hadHydrated);
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
hadHydrated = true;
setMounted(true);
}, []);

// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/rules-of-hooks -- FEATURE_TOGGLE never changes
const pageContext = React.useContext(PageContext);
Expand All @@ -30,7 +40,7 @@ export default function AppFrameBanner() {
if (showSurveyMessage) {
message = `Influence ${productName}'s 2024 roadmap! Participate in the latest Developer Survey`;
href = 'https://tally.so/r/3Ex4PN?source=website';
} else if (isBlackFriday()) {
} else if (mounted && isBlackFriday()) {
message = `Black Friday is here! Don't miss out on the best offers of the year.`;
href = 'https://mui.com/store/bundles/?deal=black-friday&from=docs';
}
Expand Down
22 changes: 10 additions & 12 deletions docs/src/modules/components/AppFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,22 @@ export function NextNProgressBar() {
const sx = { minWidth: { sm: 160 } };

const AppSearch = React.lazy(() => import('docs/src/modules/components/AppSearch'));
let hadHydrated = false;

export function DeferredAppSearch() {
const [mounted, setMounted] = React.useState(false);
const [mounted, setMounted] = React.useState(hadHydrated);
React.useEffect(() => {
hadHydrated = true;
setMounted(true);
}, []);

return (
<React.Fragment>
{/* Suspense isn't supported for SSR yet */}
{mounted ? (
<React.Suspense fallback={<Box sx={sx} />}>
<AppSearch sx={sx} />
</React.Suspense>
) : (
<Box sx={sx} />
)}
</React.Fragment>
/* Suspense isn't supported for SSR yet */
return mounted ? (
<React.Suspense fallback={<Box sx={sx} />}>
<AppSearch sx={sx} />
</React.Suspense>
) : (
<Box sx={sx} />
);
}

Expand Down
Loading