Skip to content

Commit

Permalink
Merge pull request #751 from CodeForAfrica/fix/robot_ui_fouc
Browse files Browse the repository at this point in the history
@/Roboshield fix FOUC bug
  • Loading branch information
m453h authored Jul 3, 2024
2 parents 44b7bf9 + 07c9473 commit 6c26fd0
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 460 deletions.
1 change: 1 addition & 0 deletions apps/roboshield/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@emotion/styled": "^11.11.5",
"@mui/icons-material": "^5.15.20",
"@mui/material": "^5.15.20",
"@mui/material-nextjs": "^5.15.11",
"@mui/utils": "^5.15.20",
"@mui/x-date-pickers": "^7.7.1",
"@next/env": "^14.2.4",
Expand Down
9 changes: 4 additions & 5 deletions apps/roboshield/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ import React, { ReactNode } from "react";
import Page from "@/roboshield/components/Page";
import { GlobalProvider } from "@/roboshield/context/GlobalContext";
import theme from "@/roboshield/theme";
import createEmotionCache from "@/roboshield/utils/createEmotionCache";
const clientSideEmotionCache = createEmotionCache();
import { AppCacheProvider } from "@mui/material-nextjs/v14-pagesRouter";

function getDefaultLayout(page: ReactNode, pageProps: any) {
return <Page {...pageProps}>{page}</Page>;
}

export default function App(props: AppProps | any) {
const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
const { Component, pageProps } = props;
const getLayout = Component.getLayout || getDefaultLayout;

return (
<>
<CacheProvider value={emotionCache}>
<AppCacheProvider {...props}>
<Head>
<meta name="viewport" content="initial-scale=1, width=device-width" />
<title>RoboShield</title>
Expand All @@ -31,7 +30,7 @@ export default function App(props: AppProps | any) {
{getLayout(<Component {...pageProps} />, pageProps)}
</GlobalProvider>
</ThemeProvider>
</CacheProvider>
</AppCacheProvider>
</>
);
}
30 changes: 27 additions & 3 deletions apps/roboshield/src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import { Html, Head, Main, NextScript } from "next/document";
import * as React from "react";
import {
Html,
Head,
Main,
NextScript,
DocumentProps,
DocumentContext,
} from "next/document";
import {
DocumentHeadTags,
DocumentHeadTagsProps,
documentGetInitialProps,
} from "@mui/material-nextjs/v14-pagesRouter";

export default function Document() {
export default function MyDocument(
props: DocumentProps & DocumentHeadTagsProps,
) {
return (
<Html lang="en">
<Head />
<Head>
<link rel="shortcut icon" href="/favicon.ico" />
<meta name="emotion-insertion-point" content="" />
<DocumentHeadTags {...props} />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}

MyDocument.getInitialProps = async (ctx: DocumentContext) => {
const finalProps = await documentGetInitialProps(ctx);
return finalProps;
};
20 changes: 0 additions & 20 deletions apps/roboshield/src/utils/createEmotionCache.ts

This file was deleted.

Loading

0 comments on commit 6c26fd0

Please sign in to comment.