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

ScrollYOffset is always set to 0 when the page is refreshed #162

Closed
jeff1010322 opened this issue Apr 4, 2022 · 4 comments
Closed

ScrollYOffset is always set to 0 when the page is refreshed #162

jeff1010322 opened this issue Apr 4, 2022 · 4 comments
Labels
bug Something isn't working styles

Comments

@jeff1010322
Copy link
Contributor

jeff1010322 commented Apr 4, 2022

ScrollYOffset option seems to work if you navigate to a page already loaded, but if you refresh or navigate directly to an API page the offset gets set to 0. So the sidebar will scroll under the navbar.

This affects the examples as well, so you can see what happens by directly navigating here and scrolling: https://redocusaurus.vercel.app/examples/using-single-yaml/

Screen Shot 2022-04-04 at 8 08 47 AM

It seems that this is issues is related to this line:

scrollYOffset: isBrowser ? redocOptions.scrollYOffset : 0,

It seems this is in place to prevent the warning that appears when using a selector on a direct page load:

scrollYOffset value is a selector to non-existing element. Using offset 0 by default

I don't know how to preserve the offset if you want to use a selector, but it would at least be nice to keep the value if you set it to something other than a selector.

@jeff1010322
Copy link
Contributor Author

I took a shot at creating a partial fix for this issue. See the linked PR. Basically just keeping the logic to disable this option when it is set to a selector.

With this change you could fix the examples by changing the redoc options here to use a number:
https://github.com/rohit-gohri/redocusaurus/blob/main/website/docusaurus.config.js#L50

Like this:

      options: { disableSearch: true, scrollYOffset: 60 },

I couldn't find a solution to actually allow selectors to load correctly, however.

@rohit-gohri
Copy link
Owner

Merging that fix for now to unblock you, will fix actual issue later

@rohit-gohri
Copy link
Owner

Released in v1.0.2

@benfoster
Copy link

I faced the same issue and couldn't get a selector to work either e.g. .navbar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working styles
Projects
None yet
Development

No branches or pull requests

3 participants