Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refactor document error and 404 pages

Abhinav2ee1a4aeb14e
diff --git a/apps/auth/src/pages/404.tsx b/apps/auth/src/pages/404.tsx
index b729010299..6d10e4dfb5 100644
--- a/apps/auth/src/pages/404.tsx
+++ b/apps/auth/src/pages/404.tsx
@@ -1,20 +1,17 @@
-import { VerticallyCentered } from '@ente/shared/components/Container';
-import React, { useContext, useEffect, useState } from 'react';
-import { t } from 'i18next';
-
-import { AppContext } from './_app';
-import EnteSpinner from '@ente/shared/components/EnteSpinner';
+import NotFoundPage from '@ente/shared/next/pages/404';
+import { useRouter } from 'next/router';
+import { AppContext } from 'pages/_app';
+import { useContext } from 'react';
+import { APPS } from '@ente/shared/apps/constants';
export default function NotFound() {
const appContext = useContext(AppContext);
- const [loading, setLoading] = useState(true);
- useEffect(() => {
- appContext.showNavBar(true);
- setLoading(false);
- }, []);
+ const router = useRouter();
return (
- <VerticallyCentered>
- {loading ? <EnteSpinner /> : t('NOT_FOUND')}
- </VerticallyCentered>
+ <NotFoundPage
+ appContext={appContext}
+ router={router}
+ appName={APPS.AUTH}
+ />
);
}
diff --git a/apps/auth/src/pages/_document.tsx b/apps/auth/src/pages/_document.tsx
index 97085e2b32..c3686b6be9 100644
--- a/apps/auth/src/pages/_document.tsx
+++ b/apps/auth/src/pages/_document.tsx
@@ -1,110 +1,7 @@
-import React from 'react';
-import Document, {
- Html,
- Head,
- Main,
- NextScript,
- DocumentProps,
- DocumentContext,
-} from 'next/document';
+import DocumentPage, {
+ EnteDocumentProps,
+} from '@ente/shared/next/pages/_document';
-import createEmotionServer from '@emotion/server/create-instance';
-import { AppType } from 'next/app';
-import createEmotionCache from '@ente/shared/themes/createEmotionCache';
-import { EnteAppProps } from '@ente/shared/apps/types';
-
-interface EnteDocumentProps extends DocumentProps {
- emotionStyleTags: JSX.Element[];
-}
-
-export default function EnteDocument({ emotionStyleTags }: EnteDocumentProps) {
- return (
- <Html lang="en">
- <Head>
- <meta
- name="description"
- content="ente – end-to-end encrypted cloud with open-source apps"
- />
- <link rel="icon" href="/images/favicon.png" type="image/png" />
- <link rel="manifest" href="manifest.json" />
- <link rel="apple-touch-icon" href="/images/ente/512.png" />
- <meta name="theme-color" content="#111" />
- <link rel="icon" type="image/png" href="/images/favicon.png" />
- <meta name="apple-mobile-web-app-capable" content="yes" />
- <meta
- name="apple-mobile-web-app-status-bar-style"
- content="black"
- />
- {emotionStyleTags}
- </Head>
- <body>
- <Main />
- <NextScript />
- </body>
- </Html>
- );
+export default function Document(props: EnteDocumentProps) {
+ return <DocumentPage {...props} />;
}
-
-// `getInitialProps` belongs to `_document` (instead of `_app`),
-// it's compatible with static-site generation (SSG).
-EnteDocument.getInitialProps = async (ctx: DocumentContext) => {
- // Resolution order
- //
- // On the server:
- // 1. app.getInitialProps
- // 2. page.getInitialProps
- // 3. document.getInitialProps
- // 4. app.render
- // 5. page.render
- // 6. document.render
- //
- // On the server with error:
- // 1. document.getInitialProps
- // 2. app.render
- // 3. page.render
- // 4. document.render
- //
- // On the client
- // 1. app.getInitialProps
- // 2. page.getInitialProps
- // 3. app.render
- // 4. page.render
-
- const originalRenderPage = ctx.renderPage;
-
- // You can consider sharing the same Emotion cache between all the SSR requests to speed up performance.
- // However, be aware that it can have global side effects.
- const cache = createEmotionCache();
- // eslint-disable-next-line @typescript-eslint/unbound-method
- const { extractCriticalToChunks } = createEmotionServer(cache);
-
- ctx.renderPage = () =>
- originalRenderPage({
- enhanceApp: (
- App: React.ComponentType<
- React.ComponentProps<AppType> & EnteAppProps
- >
- ) =>
- function EnhanceApp(props) {
- return <App emotionCache={cache} {...props} />;
- },
- });
-
- const initialProps = await Document.getInitialProps(ctx);
- // This is important. It prevents Emotion to render invalid HTML.
- // See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153
- const emotionStyles = extractCriticalToChunks(initialProps.html);
- const emotionStyleTags = emotionStyles.styles.map((style) => (
- <style
- data-emotion={`${style.key} ${style.ids.join(' ')}`}
- key={style.key}
- // eslint-disable-next-line react/no-danger
- dangerouslySetInnerHTML={{ __html: style.css }}
- />
- ));
-
- return {
- ...initialProps,
- emotionStyleTags,
- };
-};
diff --git a/apps/auth/src/pages/_error.tsx b/apps/auth/src/pages/_error.tsx
index 9160c65cf7..6c068e34b8 100644
--- a/apps/auth/src/pages/_error.tsx
+++ b/apps/auth/src/pages/_error.tsx
@@ -1,17 +1,17 @@
-import * as Sentry from '@sentry/nextjs';
-import NextErrorComponent from 'next/error';
+import ErrorPage from '@ente/shared/next/pages/_error';
+import { useRouter } from 'next/router';
+import { AppContext } from 'pages/_app';
+import { useContext } from 'react';
+import { APPS } from '@ente/shared/apps/constants';
-const CustomErrorComponent = (props) => (
- <NextErrorComponent statusCode={props.statusCode} />
-);
-
-CustomErrorComponent.getInitialProps = async (contextData) => {
- // In case this is running in a serverless function, await this in order to give Sentry
- // time to send the error before the lambda exits
- await Sentry.captureUnderscoreErrorException(contextData);
-
- // This will contain the status code of the response
- return NextErrorComponent.getInitialProps(contextData);
-};
-
-export default CustomErrorComponent;
+export default function Error() {
+ const appContext = useContext(AppContext);
+ const router = useRouter();
+ return (
+ <ErrorPage
+ appContext={appContext}
+ router={router}
+ appName={APPS.AUTH}
+ />
+ );
+}