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

Fix docs crash when navigating with hotkeys #6861

Merged
merged 4 commits into from
Jun 27, 2024
Merged

Conversation

evansjohnson
Copy link
Contributor

Fixes #6381

Checklist

  • [n/a] Includes tests
  • [n/a] Update documentation

Changes proposed in this pull request:

Ignore non-navigational headers so that navigating with hotkeys does not crash the page, and users cannot get to a page with no useful info.

Reviewers should focus on:

  • Unintended changes
  • Any ideas on improving the targeting of non-navigational headers

Also considered

Allowing these headers to be navigated to, but you end up on a useless page
Screenshot 2024-06-24 at 2 40 15 PM

Screenshot

Current:
Screenshot 2024-06-24 at 2 38 05 PM

This PR:
Screenshot 2024-06-24 at 2 38 15 PM

@evansjohnson evansjohnson requested a review from gluxon June 24, 2024 18:40
@changelog-app
Copy link

changelog-app bot commented Jun 24, 2024

Generate changelog in packages/docs-app/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Fix docs crash when navigating with hotkeys


Generate changelog in packages/docs-theme/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Fix docs crash when navigating with hotkeys


Check the box to generate changelog(s)

  • Generate changelog entry

} else if (isPageNode(node)) {
this.routeToPage[node.route] = node.reference;
} else if (parents[0] != null) {
this.routeToPage[node.route] = parents[0].reference;
Copy link
Contributor Author

@evansjohnson evansjohnson Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ! was probably fine but no reason to not gracefully fail here I think rather than error out if we end up with something unexpected

@svc-palantir-github
Copy link

fix nav issue with docs page

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@gluxon gluxon self-assigned this Jun 24, 2024
Comment on lines 171 to 172
if (isNavSection(node)) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Might be worth a comment that we never want to put the user on a "nav section" since these aren't click-able and don't have a real page. They're just presentational groupings of pages.

Comment on lines 125 to 135
// HACKHACK: this is brittle
// detect Components page and subheadings
const COMPONENTS_PATTERN = /\/components(\.[\w-]+)?$/;
const CONTEXT_PATTERN = /\/context(\.[\w-]+)?$/;
const HOOKS_PATTERN = /\/hooks(\.[\w-]+)?$/;
const LEGACY_PATTERN = /\/legacy(\.[\w-]+)?$/;
export const isNavSection = ({ route }: HeadingNode) =>
COMPONENTS_PATTERN.test(route) ||
CONTEXT_PATTERN.test(route) ||
HOOKS_PATTERN.test(route) ||
LEGACY_PATTERN.test(route);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this from docs-app to docs-theme feels a bit strange. I think docs-theme is meant to be generalizable outside of the Blueprint repo, and these regex patterns look specific to Blueprint's docs-app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I didn't understand what the distinction was for, I suppose some other project could rely on docs-theme to use the blueprint docs styling and provide their own content?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! I think that's the intention. I'm not sure how many other projects actually do that though.

this.routeToPage[node.route] = reference;
if (isNavSection(node)) {
return;
} else if (isPageNode(node)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the "components" navigation section passing the isPageNode check? Could that be a bug in Documentalist or are we setting up the components section in a weird/unexpected way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going on intuition haven't dug into the code much here but I believe "components" is a page node because it has sub-pages - /docs/#core/components/breadcrumbs

const navItemElement = this.navElement.querySelector<HTMLElement>(`a[href="#${activeSectionId}"]`)!;
const navItemElement = this.navElement.querySelector<HTMLElement>(`a[href="#${activeSectionId}"]`);
if (navItemElement == null) {
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what was actually crashing, and is all that is needed to avoid crashing. but without the rest of this diff users end up here which isn't really useful/seems like a bug on it's own

Screenshot 2024-06-24 at 2 40 15 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree!

@evansjohnson evansjohnson requested a review from gluxon June 27, 2024 13:33
@svc-palantir-github
Copy link

diff

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Copy link
Contributor

@gluxon gluxon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🥳

const { reference } = isPageNode(node) ? node : parents[0]!;
this.routeToPage[node.route] = reference;
if (isPageNode(node)) {
if (this.props.navigatorExclude?.(node)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice! I see we were already setting this prop.

const navItemElement = this.navElement.querySelector<HTMLElement>(`a[href="#${activeSectionId}"]`)!;
const navItemElement = this.navElement.querySelector<HTMLElement>(`a[href="#${activeSectionId}"]`);
if (navItemElement == null) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree!

@evansjohnson evansjohnson merged commit ceea422 into develop Jun 27, 2024
12 of 14 checks passed
@evansjohnson evansjohnson deleted the evanj/docs-nav-fix branch June 27, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hotkey navigation on blueprintjs.com/docs sometimes makes the page crash
3 participants