question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gatsby-remark-autolink-headers not reading the offsetY option set in gatsby-config.js

See original GitHub issue

Description

Hello, I am trying to use gatsby-remark-autolink-headers to add header links to my markdown pages. I have set the offsetY to 100, however when I click the header it snaps it to the very top of the page. The other options seem to work, so I’m not sure why just the offsetY option is not working.

Steps to reproduce

Minimal Reproduction: https://github.com/Aarya-Patel/gatsby-reproduction Steps to reproduce:

  1. run npm install --legacy-peer-deps
  2. run gatsby develop
  3. Head over to ‘/second-post’ path.
  4. Click the links.

Expected result

There should be a 100px offset from the top when clicking the header links.

Actual result

There is no 100px offset from the top when clicking the header links.

Environment

System: OS: macOS 11.0.1 CPU: (8) x64 Intel® Core™ i7-8569U CPU @ 2.80GHz Shell: 3.2.57 - /bin/bash Binaries: Node: 15.0.0 - ~/.nvm/versions/node/v15.0.0/bin/node npm: 7.0.2 - ~/.nvm/versions/node/v15.0.0/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Chrome: 91.0.4472.77 Safari: 14.0.1 npmPackages: gatsby: ^3.6.2 => 3.6.2 gatsby-core-utils: ^2.6.0 => 2.6.0 gatsby-plugin-gatsby-cloud: ^2.6.1 => 2.6.1 gatsby-plugin-image: ^1.6.0 => 1.6.0 gatsby-plugin-manifest: ^3.6.0 => 3.6.0 gatsby-plugin-offline: ^4.6.0 => 4.6.0 gatsby-plugin-react-helmet: ^4.6.0 => 4.6.0 gatsby-plugin-sharp: ^3.6.0 => 3.6.0 gatsby-plugin-sitemap: ^4.2.0 => 4.2.0 gatsby-remark-autolink-headers: ^4.3.0 => 4.3.0 gatsby-source-filesystem: ^3.6.0 => 3.6.0 gatsby-transformer-remark: ^4.3.0 => 4.3.0 gatsby-transformer-sharp: ^3.6.0 => 3.6.0 npmGlobalPackages: gatsby-cli: 3.6.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
MangelMaximecommented, Jul 24, 2021

Looking at the source code of the plugin I saw this lines:

https://github.com/gatsbyjs/gatsby/blob/2dbe6477d88bf6e0138f247dc9dda1bd67a2a613/packages/gatsby-remark-autolink-headers/src/gatsby-browser.js#L15-L18

It seems like the plugin is not only using offsetY to control the offset but also take into consideration both of these properties.

I added a CSS rule to set one of these properties and it seems to be working for me.

.content {
    h1[id],
    h2[id],
    h3[id],
    h4[id],
    h5[id],
    h6[id] {
        scroll-margin-top: 3.5rem;
    }
}
1reaction
MangelMaximecommented, Jul 24, 2021

I just encountered the same issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-remark-autolink-headers doesn't apply offset when ...
Description If the history updates without the update originating from a Link component onRouteUpdate won't fire, eg. Scroll to some id.
Read more >
gatsby-remark-autolink-headers
This is a sub-plugin for gatsby-transformer-remark . As demoed below, add this plugin to the options of gatsby-transformer-remark .
Read more >
gatsby-plugin-mdx with rehype-autolink-headers only working ...
I am using the below config in gatsby-config.js and cleared .cache and public after updating the file to be sure nothing was cached....
Read more >
Installing builder.io in allready gatsby app - Technical Questions
Hi, After installing @builder.io/gatsby into a web app using Gatsby I'm getting errors: Cannot read property 'allBuilderModels' of undefined.
Read more >
A Walkthrough of migrating MaxRozen.com from Gatsby to ...
macro to get the same CSS-in-JS + Tailwind setup I was using with Gatsby. Folder structure and file naming. The examples in Next.js'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found