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

Page jumps to the top on HMR changes in some cases #1341

Open
hughess opened this issue Nov 17, 2023 · 3 comments
Open

Page jumps to the top on HMR changes in some cases #1341

hughess opened this issue Nov 17, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@hughess
Copy link
Member

hughess commented Nov 17, 2023

I think this might be caused by charts - when an HMR change is made to one chart, they all re-trigger and re-animate. I think when the first chart is close to the top of the page, somehow that triggers the page to jump up to the top to show the update.

Scenarios

1. Lots of text, chart 1 at bottom

Works

pagejumpcase1

2. Now add DataTable to the top

Still works

pagejumpcase2

3. Now replace that DataTable with a chart

Jumps to top

pagejumpcase3

4. Now move the first chart down under the text

This works, but both charts re-animated

pagejumpcase4

5. Move the first chart into the middle of the text content

Works

pagejumpcase5

6. Move the first chart about 25% into the text content (closer to top)

Jumps to top of page

pagejumpcase6

Expected Behavior

Page should stay where it is on any HMR change

@hughess hughess added bug Something isn't working to-review Evidence team to review labels Nov 17, 2023
@mcrascal mcrascal added high-priority Bug significantly impacting the Evidence UX for many users. Immediate fix and removed to-review Evidence team to review labels Nov 20, 2023
@mcrascal mcrascal removed the high-priority Bug significantly impacting the Evidence UX for many users. Immediate fix label Feb 20, 2024
@smilingthax
Copy link

When I encounter this Problem, the initial load DOM contains:

<h2 class="markdown" id="4">Some Section</h2>

but after HMR it's just:

<h2 class="markdown">Some Section</h2>

I.e. the idattribute is missing. Also, the right sidebar navigation (Sections on the Page) stops working (URL changes to include #4, but there's no such anchor position in the DOM any more).
I suppose this also causes the repositioning after HMR to fail.

@archiewood
Copy link
Member

archiewood commented Mar 20, 2024

Having looked at this problem recently (id generation and navigation), there are some issues with the way we add the Table of Contents.

The TOC and anchor links are generated client side (and not during prebuild)

I think the design reason for this is that in principle, user interaction could change what headings exist on the page (eg change the number of rows that are looped through, change the heading text etc.

This is suboptimal because it means that you cannot navigate from another site or page in an evidence project to an anchor link

@smilingthax
Copy link

I see... unfortunately, putting the MutationObserver on <article> will trigger it very often (e.g just by moving the mouse over a graph, tooltips are added to/removed from the dom), and although after HMR then the <h2> tags regained their id, this did not fix the jump-to-top problem in my short experiment...

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

No branches or pull requests

4 participants