fix(gatsby-remark-autolink-headers): use offsetY prop as scroll-margin-top #36961
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
There is an issue with the plugin (gatsby-remark-autolink-headers) when
offsetY
prop is passed.On initial load of a page with hash (like #heading-1), scroll moves to the expected position (with offsetY calculated). But then if you click another link with hash in that page, offset is ignored.
I guess the reason of this behavior might be that it is changing scroll position programatically, in
gatsby-browser.js
and some script ingatsby-ssr.js
.So why not just use
scroll-margin-top
css property and default behavior of the browser?I just added
scroll-margin-top
to the headings when offsetY is passed. Deletedgatsby-browser.js
and just commented out the script code ingatsby-ssr.js
because I wasn't sure if it's ok to delete the existing comments.Please let me know if some changes has to be made.
Documentation
https://github.com/sanginchun/gatsby/tree/master/packages/gatsby-remark-autolink-headers
Related Issues
I think the unexpected behavior that I explained above is related to #26169