-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
What??
The issue title is a bit of a joke but its just describing a funny end result of what was probably a minor oversight when generating the docs for v10
.
This started when I tried to find info on npm scripts that run after specific npm commands like "postinstall": ""
. Capacitor calls them hooks (maybe some other projects do too idk) so I figured I'd search the "Hooks" in the search box, but as soon as I typed the first letter "H" this happened
The site completely crashed immediately after I typed "H" ("h" also breaks). I can get this to happen every time in both Chrome and Firefox and no other query does this (not exactly true "npm-h" also breaks it).
I pulled the code for the site and tested it locally and turns out the issue is that search finds the article at /cli/v10/commands/npm-hook
(https://github.com/npm/documentation/blob/main/content/cli/v10/commands/npm-hook.mdx) but when <SearchResults/>
tries to match its path to bread crumbs it gets an empty array and then tries reading a negative index.
It gets no breadcrumb results since there's no entry for npm-hook
under v10
in content/nav.yml
Lines 1404 to 1408 in f4898d9
url: /cli/v10/commands/npm-help-search | |
description: Get help on npm | |
- title: npm init | |
url: /cli/v10/commands/npm-init | |
description: Create a package.json file |
which I'm assuming is related to the fact that the hooks api was deprecated - https://github.blog/changelog/2024-07-16-sunset-notice-npm-hooks-api-endpoints/
Fix
I was able to fix the issue with three different approaches:
1. Don't access invalid index
This is just adding a check in src/components/search.js
to see if hierarchy
is empty which sort of fixes the issue but for some reason if you select the result for npm-hook
the version dropdown on the doc page for it ends up being empty.
2. Delete the page
Deleting https://github.com/npm/documentation/blob/main/content/cli/v10/commands/npm-hook.mdx fixes the issue too but that only make sense if that page really wasn't intended to exist in the first place. I'd assume thats the correct approach but it looks like npm hook
is still a command on npm v10
3. Add a nav entry
This lets setNav.getItemBreadcrumbs(item.path)
actually return some results so <SearchResults/>
doesn't break but adding the nav entry probably only makes sense if the page cli/v10/commands/npm-hook
was intended to exist.
I would just make a PR with a fix but I don't know if the page for npm-hook
should even exist under v10 or not so idk which route to go with.