Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/app/pages/404/404.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React from 'react';
import useDocumentHead from '~/helpers/use-document-head';
import useLayoutContext from '~/contexts/layout';

export default function Page() {
useDocumentHead({
title: '404 Not Found - OpenStax',
noindex: true
});
const {layoutParameters, setLayoutParameters} = useLayoutContext();

if (layoutParameters.name === null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this make loading a 404 page in a portal flash the main nav while the page data is loading?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I can see. A top-level portal page won't do a 404 because it has to exist in the CMS to be a portal page. A lower-level page within the portal doesn't load until the layout parameters are set, so this if condition isn't met.

setLayoutParameters();
}
Comment on lines +10 to +14

return (
<main className="not-found no-style page">
Expand Down
5 changes: 4 additions & 1 deletion test/src/components/loader-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {render, screen} from '@testing-library/preact';
import { LoadedPage } from '~/components/jsx-helpers/loader-page';
import MemoryRouter from '~/../../test/helpers/future-memory-router';
import { LayoutContextProvider } from '~/contexts/layout';

describe('loader-page', () => {
// The rest of the code is exercised in other tests.
Expand All @@ -13,7 +14,9 @@ describe('loader-page', () => {

render(
<MemoryRouter initialEntries={['/testpage']}>
<LoadedPage data={data} Child={Child} props={{}} />
<LayoutContextProvider>
<LoadedPage data={data} Child={Child} props={{}} />
</LayoutContextProvider>
</MemoryRouter>
);
Comment on lines +17 to 21

Expand Down
Loading