Skip to content

fix(compontent): fix links with undefined in docs-table-of-contents.js #19851

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

Merged

Conversation

muescha
Copy link
Contributor

@muescha muescha commented Nov 28, 2019

Description

Missing header element

there are some mdx that have left off a header in the tree:

## 2. Header

#### 4. Header 

Examples:

Current Result

then an element is inserted to the header array with just items::

{ 
  url: '#2header', 
  title: '2. Header', 
  items:
    [
      { 
        items: 
	      [ 
		    { 
              url: '#4header', 
              title: '4. Header' 
            }
          ]
      }
    ]
}

it creates:

  • then the TOC create empty Links with undefined in href:
<a class="css-1wk9u7" href="/docs/how-code-splitting-works/undefined"></a>
  • it creates a:
<link rel="prefetch" href="/page-data/docs/how-code-splitting-works/undefined/page-data.json" crossorigin="anonymous" as="fetch">

Fixed Result

  • removed Link element when item.url is undefined
  • changed the key for the li item
  • prefetch links for the undefined links are not created

Related Issues

#19267

@muescha muescha requested a review from a team as a code owner November 28, 2019 04:26
@muescha
Copy link
Contributor Author

muescha commented Dec 11, 2019

Screenshot

Bildschirmfoto 2019-12-11 um 12 05 06

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

It looks good to me.

Separate issue is the fact that we have content with headings that skip a level (ideally we fix this stuff in our docs, but we shouldn't display empty undefined links in case there is heading hierarchy gaps.

Thanks @muescha!

@pieh pieh merged commit 4e2b8ab into gatsbyjs:master Dec 11, 2019
@muescha muescha deleted the muescha/fix/undefined-in-toc-component branch December 11, 2019 17:18
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.

2 participants