docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Customized 404 not applied for docs/ sub routes

Open peterpeterparker opened this issue 1 year ago • 1 comments

Have you read the Contributing Guidelines on issues?

Prerequisites

  • [X] I'm using the latest version of Docusaurus.
  • [X] I have tried the npm run clear or yarn clear command.
  • [X] I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • [X] I have tried creating a repro with https://new.docusaurus.io.
  • [X] I have read the console error message carefully (if applicable).

Description

Follow-up of discussion #9664.

It seems that swizzled 404 are resolved when a root URL is accessed but, not when a sub-route is loaded.

e.g.

http://localhost:3000/unknown -> custom 404 http://localhost:3000/docs/unknown -> default 404 (or custom 404 for a milli seconds and default afterwards)

Reproducible demo

No response

Steps to reproduce

git clone https://github.com/peterpeterparker/docusaurus-404 cd docusaurus-404 npm ci npm run start

try various unknown routes

Expected behavior

Custom 404 displayed for any 404 regardless of the (sub)route.

Actual behavior

As described in the details.

Your environment

No response

Self-service

  • [ ] I'd be willing to fix this bug myself.

peterpeterparker avatar Dec 22 '23 18:12 peterpeterparker

Looks like only for the docs route, the 404 content comes from NotFoundContent. As the DocRoot 404 is having this - https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-classic/src/theme/DocRoot/index.tsx#L24

This was added to fix double layout issue for 404 in docs - https://github.com/facebook/docusaurus/pull/7966/commits/ca177b358d9be189c81f78f2c1841fb02f0f246e

Maybe we have to update swizzle plugin to emit or wrap NotFoundContent component instead of NotFound. Instead of this docusaurus swizzle "@docusaurus/theme-classic" "NotFound" it should be changed to docusaurus swizzle "@docusaurus/theme-classic" "NotFoundContent".

Or else we have to move the content from NotFound.js to NotFoundContent.js, that should fix this issue and somehow make sure this is documented.

murali-krishna-sv avatar Dec 29 '23 14:12 murali-krishna-sv