Skip to content

Fix: WordPress anchor links requiring two clicks - use smart click ha…#265

Closed
ralvarez-dg wants to merge 1 commit into
mainfrom
anchor-fix
Closed

Fix: WordPress anchor links requiring two clicks - use smart click ha…#265
ralvarez-dg wants to merge 1 commit into
mainfrom
anchor-fix

Conversation

@ralvarez-dg

Copy link
Copy Markdown
Contributor

…ndler instead of timeout

Description

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (BREAKING CHANGE:)
  • Refactor / chore (refactor: / chore:)
  • Documentation update (docs:)

Affected package(s)

  • @devgateway/dvz-ui-react
  • @devgateway/wp-react-lib
  • example only (no changeset needed)

Checklist

  • PR title follows Conventional Commits format
  • A changeset has been added (pnpm changeset) for any change to a published package
  • pnpm build passes locally
  • pnpm --filter @devgateway/* typecheck passes
  • No hardcoded credentials, internal URLs, client names, or PII introduced
  • Any new dependency has an Apache-2.0-compatible license

Copilot AI review requested due to automatic review settings July 1, 2026 15:00
@ralvarez-dg ralvarez-dg closed this Jul 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes in-page anchor navigation behavior (notably for WordPress-rendered content) by handling hash-based scrolling on initial load and intercepting #... anchor clicks to scroll without relying on a single delayed timeout.

Changes:

  • Replace the fixed setTimeout-based hash scroll with a retry-based initial-hash handler.
  • Add a delegated document click handler for #... anchor links to update the URL and scroll smoothly.

Comment on lines +64 to +68
const handleAnchorClick = (e: MouseEvent) => {
const target = e.target as HTMLElement;
if (target.tagName === 'A') {
const href = target.getAttribute('href');
if (href && href.startsWith('#')) {
Comment on lines +83 to +90
document.addEventListener('click', handleAnchorClick as any);

// Handle initial page load
handleInitialHash();

return () => {
document.removeEventListener('click', handleAnchorClick as any);
};
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