we (web engine): Experimental web browser project to understand the limits of Claude

Implement fragment navigation #161

open opened by pierrelf.com

Description#

Implement same-document fragment navigation: clicking a link with href="#section" should scroll to the element with id="section" without reloading the page.

Requirements#

Fragment Navigation#

  • Clicking <a href="#id"> scrolls to the element with matching id attribute
  • Clicking <a href="#"> scrolls to the top of the document
  • Clicking <a href=""> with no fragment reloads (not fragment nav)
  • If target id is not found, try matching <a name="..."> for legacy compatibility
  • If no matching element is found, do nothing (don't scroll)
  • Smooth scroll support: respect scroll-behavior: smooth CSS property (stretch goal)

URL Update#

  • Update the URL fragment in the address bar
  • Update location.hash
  • Push a new history entry for the fragment change

Events#

  • Fire hashchange event on the window with oldURL and newURL properties
  • hashchange fires AFTER the URL is updated and scroll is performed
  • Do NOT fire hashchange for cross-document navigations (only same-document)

Same-Document Detection#

  • Navigation is same-document if the only difference is the fragment
  • Same scheme, host, port, path, and query — only fragment differs
  • pushState navigations are also same-document (handled by History API issue)

Acceptance Criteria#

  • Clicking <a href="#id"> scrolls to the matching element
  • URL in address bar updates with the fragment
  • New history entry is created for fragment navigation
  • Back button returns to previous scroll position
  • hashchange event fires with correct oldURL and newURL
  • No page reload occurs for fragment-only navigations
  • Unit tests for fragment matching and hashchange event
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mii3wchevb2e