Skip to content

Comments

Fix fragment links not navigating to correct content#13

Merged
simonw merged 1 commit intomainfrom
claude/fix-fragment-navigation-t2Q4T
Dec 27, 2025
Merged

Fix fragment links not navigating to correct content#13
simonw merged 1 commit intomainfrom
claude/fix-fragment-navigation-t2Q4T

Conversation

@simonw
Copy link
Owner

@simonw simonw commented Dec 27, 2025

The gistpreview mechanis has a bug: fragment links like https://gistpreview.github.io/?edbd5ddcb39d1edc9e175f1bf7b9ef9a/page-001.html#msg-2025-12-26T15-30-45-910Z do not naught the user to the right point, presumably because the content has not loaded in time

Fix that with more JavaScript in the existing gistpreview JavaScript

When accessing a gistpreview URL with a fragment (e.g. #msg-2025-12-26T15-30-45-910Z), the browser's native fragment navigation fails because gistpreview loads content dynamically. By the time the browser tries to scroll to the element, it doesn't exist yet.

Added JavaScript that:

  • Checks for fragment in window.location.hash
  • Uses scrollIntoView to navigate to the target element
  • Retries with increasing delays (100ms, 300ms, 500ms, 1s) to handle dynamic content loading

https://gistpreview.github.io/?883ee001b0d63a2045f1e2c7c2598a9f/index.html

When accessing a gistpreview URL with a fragment (e.g.
#msg-2025-12-26T15-30-45-910Z), the browser's native fragment
navigation fails because gistpreview loads content dynamically.
By the time the browser tries to scroll to the element, it
doesn't exist yet.

Added JavaScript that:
- Checks for fragment in window.location.hash
- Uses scrollIntoView to navigate to the target element
- Retries with increasing delays (100ms, 300ms, 500ms, 1s) to
  handle dynamic content loading
@simonw
Copy link
Owner Author

simonw commented Dec 27, 2025

@simonw simonw merged commit 68f7395 into main Dec 27, 2025
30 checks passed
@simonw simonw deleted the claude/fix-fragment-navigation-t2Q4T branch December 27, 2025 00:54
simonw added a commit that referenced this pull request Dec 27, 2025
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