Skip to content

Add HashContext and HashProvider for managing URL hash state #3541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 8, 2025

Conversation

conico974
Copy link
Contributor

Link with an hash on the same page were not triggering change from the useHash hook.

Copy link

linear bot commented Aug 6, 2025

Copy link

changeset-bot bot commented Aug 6, 2025

⚠️ No Changeset found

Latest commit: 72d09d7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

argos-ci bot commented Aug 6, 2025

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
customers-v2 (Inspect) 👍 Changes approved 6 changed Aug 8, 2025, 2:30 PM
v2-cloudflare (Inspect) 👍 Changes approved 4 changed Aug 8, 2025, 2:56 PM
v2-vercel (Inspect) ✅ No changes detected - Aug 8, 2025, 2:33 PM

@conico974 conico974 requested a review from Copilot August 6, 2025 21:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a HashContext and HashProvider system to properly manage URL hash state changes for same-page links. The existing useHash hook was not triggering updates when clicking links with hashes on the same page, so this solution replaces the previous implementation with a context-based approach that manually tracks hash changes through the Link component.

  • Replaces the existing useHash hook implementation with a context-based solution
  • Adds HashProvider to the application's root context providers
  • Integrates hash tracking into the Link component's onClick handler

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/gitbook/src/components/primitives/Link.tsx Adds HashContext integration and calls updateHashFromUrl in onClick handler
packages/gitbook/src/components/hooks/useHash.tsx New file implementing HashContext, HashProvider, and updated useHash hook
packages/gitbook/src/components/hooks/useHash.ts Removes the old useHash implementation
packages/gitbook/src/components/RootLayout/ClientContexts.tsx Wraps the app with HashProvider

@conico974 conico974 merged commit 8784112 into main Aug 8, 2025
23 of 24 checks passed
@conico974 conico974 deleted the conico/rnd-7825-anchor-tab branch August 8, 2025 15:01
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