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
- Use a WordPress site with Gutenberg 22.7.0 enabled
- Create a page with long content and a standard HTML anchor link:
<a href="#footer">Go to Footer</a>.
- Ensure the page also has some block that requires interactivity (Ex: a core/navigation block)
- Click the Go to Footer link.
- Observed behavior: The page reloads entirely instead of simply scrolling to the ID.
- 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.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
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:When a user clicks a standard hash link, the browser creates a new history entry. Because this new state does not contain the
wpInteractivityIdassigned at the start of the session, thepopstatelistener in@wordpress/interactivityidentifies it as a stale session and executeswindow.location.reload().Step-by-step reproduction instructions
<a href="#footer">Go to Footer</a>.Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.