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

refactor(core): properly code-split NotFound page #7405

Merged
merged 1 commit into from
May 12, 2022
Merged
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
21 changes: 16 additions & 5 deletions packages/docusaurus/src/client/exports/ComponentCreator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import registry from '@generated/registry';
import flat from '../flat';
import {RouteContextProvider} from '../routeContext';

declare global {
interface NodeRequire {
resolveWeak: (name: string) => number;
}
}

export default function ComponentCreator(
path: string,
hash: string,
Expand All @@ -21,14 +27,19 @@ export default function ComponentCreator(
if (path === '*') {
return Loadable({
loading: Loading,
loader: () =>
import('@theme/NotFound').then(({default: NotFound}) => (props) => (
loader: () => import('@theme/NotFound'),
modules: ['@theme/NotFound'],
webpack: () => [require.resolveWeak('@theme/NotFound')],
render(loaded, props) {
const NotFound = loaded.default;
return (
<RouteContextProvider
// Do we want a better name than native-default?
value={{plugin: {name: 'native', id: 'default'}}}>
<NotFound {...(props as never)} />
<NotFound {...(props as JSX.IntrinsicAttributes)} />
</RouteContextProvider>
)),
);
},
});
}

Expand Down Expand Up @@ -60,7 +71,7 @@ export default function ComponentCreator(
loader,
modules,
webpack: () => optsWebpack,
render: (loaded, props) => {
render(loaded, props) {
// `loaded` will be a map from key path (as returned from the flattened
// chunk names) to the modules loaded from the loaders. We now have to
// restore the chunk names' previous shape from this flat record.
Expand Down