docs icon indicating copy to clipboard operation
docs copied to clipboard

[Docs Site] Custom404 should be based on content, not platform/pathname

Open ericclemmons opened this issue 4 years ago • 1 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

When using the Layout component in our UI docs (yarn docs add amplify-docs@github:https://github.com/aws-amplify/docs#next), Next.js would crash with a SIGABRT & heap allocation (memory) error.

When debugging, it seems that the check below for Custom404 was the culprit.

Here is the diff that solved my problem:

diff --git a/node_modules/amplify-docs/src/components/Layout/index.tsx b/node_modules/amplify-docs/src/components/Layout/index.tsx
index ba3982a..c402336 100644
--- a/node_modules/amplify-docs/src/components/Layout/index.tsx
+++ b/node_modules/amplify-docs/src/components/Layout/index.tsx
@@ -18,13 +18,17 @@ export default function Layout({children, meta}: {children: any; meta?: any}) {
   const {platform} = router.query as {platform: string};
   const headers = traverseHeadings(children, platform);
   const filters = gatherFilters(children);
-  if (
-    !filters.includes(platform) &&
-    !pathname.includes("start") &&
-    !pathname.includes("404")
-  ) {
-    return Custom404();
-  }
+
+  // ❗️ This causes an endless redirect – Node crashes with a SIGABRT when using `Layout`
+  // outside of this project & in other Next.js pages. Presumably because `platform` & `pathname` are falsey.
+  // 
+  // if (
+  //   !filters.includes(platform) &&
+  //   !pathname.includes("start") &&
+  //   !pathname.includes("404")
+  // ) {
+  //   return Custom404();
+  // }
   const basePath = "docs.amplify.aws";
   return (
     <>

My recommendation is that getStaticPaths returns all known paths to content to correctly return a 404 vs. using this fallback.

If this isn't possible, then should the presence of children indicate a 200/400?

This issue body was partially generated by patch-package.

ericclemmons avatar Jul 08 '21 18:07 ericclemmons

@jakeburden , thoughts on this?

mauerbac avatar May 08 '22 18:05 mauerbac

This was fixed in the latest version of Amplify Docs site

reesscot avatar Feb 08 '24 23:02 reesscot