Skip to content

Interactivity API: Native anchor links (#) trigger full page reload due to wpInteractivityId mismatch #76447

@joshuadwire

Description

@joshuadwire

Description

Since the introduction of session-based history tagging in PR #75927, native anchor/hash links (e.g., <a href="#section">) cause the entire page to reload. Specifically, the issue seems to be with this portion of the PR:

window.addEventListener( 'popstate', ( event ) => {
	if ( event.state?.wpInteractivityId !== sessionId ) {
		window.location.reload();
	}
} );

When a user clicks a standard hash link, the browser creates a new history entry. Because this new state does not contain the wpInteractivityId assigned at the start of the session, the popstate listener in @wordpress/interactivity identifies it as a stale session and executes window.location.reload().

Step-by-step reproduction instructions

  1. Use a WordPress site with Gutenberg 22.7.0 enabled
  2. Create a page with long content and a standard HTML anchor link: <a href="#footer">Go to Footer</a>.
  3. Ensure the page also has some block that requires interactivity (Ex: a core/navigation block)
  4. Click the Go to Footer link.
  5. Observed behavior: The page reloads entirely instead of simply scrolling to the ID.
  6. Expected behavior: The browser should navigate to the fragment identifier without a page refresh.

Screenshots, screen recording, code snippet

No response

Environment info

  • Gutenberg 22.7.0
  • Wordpress 6.9.4
  • Exists on Chrome and Brave
  • Exists on Android and Windows

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

Labels

[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions