mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-03 12:17:20 +02:00
refactor(core): properly code-split NotFound page (#7405)
This commit is contained in:
parent
2bc3ea363f
commit
d2ca4a171c
1 changed files with 16 additions and 5 deletions
|
@ -13,6 +13,12 @@ import registry from '@generated/registry';
|
||||||
import flat from '../flat';
|
import flat from '../flat';
|
||||||
import {RouteContextProvider} from '../routeContext';
|
import {RouteContextProvider} from '../routeContext';
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface NodeRequire {
|
||||||
|
resolveWeak: (name: string) => number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function ComponentCreator(
|
export default function ComponentCreator(
|
||||||
path: string,
|
path: string,
|
||||||
hash: string,
|
hash: string,
|
||||||
|
@ -21,14 +27,19 @@ export default function ComponentCreator(
|
||||||
if (path === '*') {
|
if (path === '*') {
|
||||||
return Loadable({
|
return Loadable({
|
||||||
loading: Loading,
|
loading: Loading,
|
||||||
loader: () =>
|
loader: () => import('@theme/NotFound'),
|
||||||
import('@theme/NotFound').then(({default: NotFound}) => (props) => (
|
modules: ['@theme/NotFound'],
|
||||||
|
webpack: () => [require.resolveWeak('@theme/NotFound')],
|
||||||
|
render(loaded, props) {
|
||||||
|
const NotFound = loaded.default;
|
||||||
|
return (
|
||||||
<RouteContextProvider
|
<RouteContextProvider
|
||||||
// Do we want a better name than native-default?
|
// Do we want a better name than native-default?
|
||||||
value={{plugin: {name: 'native', id: 'default'}}}>
|
value={{plugin: {name: 'native', id: 'default'}}}>
|
||||||
<NotFound {...(props as never)} />
|
<NotFound {...(props as JSX.IntrinsicAttributes)} />
|
||||||
</RouteContextProvider>
|
</RouteContextProvider>
|
||||||
)),
|
);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +71,7 @@ export default function ComponentCreator(
|
||||||
loader,
|
loader,
|
||||||
modules,
|
modules,
|
||||||
webpack: () => optsWebpack,
|
webpack: () => optsWebpack,
|
||||||
render: (loaded, props) => {
|
render(loaded, props) {
|
||||||
// `loaded` will be a map from key path (as returned from the flattened
|
// `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
|
// chunk names) to the modules loaded from the loaders. We now have to
|
||||||
// restore the chunk names' previous shape from this flat record.
|
// restore the chunk names' previous shape from this flat record.
|
||||||
|
|
Loading…
Add table
Reference in a new issue