Skip to content

fix(mothership): fix url keeping markdown hash on resource switch#3979

Merged
TheodoreSpeaks merged 1 commit intostagingfrom
fix/resource-hashtag-url
Apr 7, 2026
Merged

fix(mothership): fix url keeping markdown hash on resource switch#3979
TheodoreSpeaks merged 1 commit intostagingfrom
fix/resource-hashtag-url

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

Summary

We recently added support for # to represent headers in markdown files. However, this needs to be cleared on switching resources. Added clearing logic.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

Validated switching resources does not keep trailing hash

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 6, 2026

PR Summary

Low Risk
Low risk, localized client-side URL update that only affects history state when activeResourceId changes; minimal chance of regressions outside navigation behavior.

Overview
Clears any trailing URL fragment (#...) whenever the active resource changes by explicitly resetting url.hash before calling window.history.replaceState.

This prevents markdown header hashes from persisting across resource switches while keeping the resource query param in sync.

Reviewed by Cursor Bugbot for commit eab6aed. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 6, 2026

Greptile Summary

This PR fixes a bug where the URL fragment (e.g., #heading-name) from markdown anchor navigation persisted in the browser URL when switching between resources on the home page. A single line — url.hash = '' — is added inside the existing useEffect that synchronizes activeResourceId with the URL, ensuring the hash is stripped on every resource switch. The fix is minimal, targeted, and correct per the WHATWG URL spec (setting .hash = '' removes the fragment identifier entirely from url.toString()).

  • Bug fixed: URL hash from markdown headings no longer persists after switching resources
  • Approach: Leverages the existing useEffect([activeResourceId]) URL-sync block — no new effect or state needed
  • Spec-compliant: Setting url.hash = '' removes the fragment identifier per the WHATWG URL Standard
  • No regressions: Change is scoped entirely to URL state; no component state, React Query, or store code is touched

Confidence Score: 5/5

This PR is safe to merge — it is a minimal, correct one-line bug fix

Single-line addition of url.hash = '' inside an existing useEffect; follows the WHATWG URL spec, integrates cleanly with existing logic, no regressions or logic errors introduced

No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/home.tsx Adds url.hash = '' in the activeResourceId useEffect to clear markdown heading hashes on resource switch

Sequence Diagram

sequenceDiagram
    actor User
    participant Home as Home Component
    participant State as activeResourceId State
    participant Effect as useEffect
    participant History as window.history

    User->>Home: Switches resource (clicks tab)
    Home->>State: setActiveResourceId(newId)
    State->>Effect: Triggers useEffect([activeResourceId])
    Effect->>Effect: url = new URL(window.location.href)
    Effect->>Effect: url.searchParams.set('resource', newId)
    Effect->>Effect: url.hash = '' (clears markdown anchor hash)
    Effect->>History: replaceState(null, '', url.toString())
    History-->>User: URL updated: ?resource=newId (no #fragment)
Loading

Reviews (1): Last reviewed commit: "fix(mothership): fix url keeping markdow..." | Re-trigger Greptile

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Hash cleared before markdown scroll on initial load
    • I now clear the URL hash only after at least one prior active resource existed and the resource actually changed, preserving deep-link hashes during initial activation.

Create PR

Or push these changes by commenting:

@cursor push e95f7481ad
Preview (e95f7481ad)
diff --git a/apps/sim/app/workspace/[workspaceId]/home/home.tsx b/apps/sim/app/workspace/[workspaceId]/home/home.tsx
--- a/apps/sim/app/workspace/[workspaceId]/home/home.tsx
+++ b/apps/sim/app/workspace/[workspaceId]/home/home.tsx
@@ -171,6 +171,7 @@
   const [editingInputValue, setEditingInputValue] = useState('')
   const [prevChatId, setPrevChatId] = useState(chatId)
   const clearEditingValue = useCallback(() => setEditingInputValue(''), [])
+  const previousActiveResourceIdRef = useRef<string | null>(null)
 
   // Clear editing value when navigating to a different chat (guarded render-phase update)
   if (chatId !== prevChatId) {
@@ -190,12 +191,16 @@
 
   useEffect(() => {
     const url = new URL(window.location.href)
+    const previousActiveResourceId = previousActiveResourceIdRef.current
     if (activeResourceId) {
       url.searchParams.set('resource', activeResourceId)
     } else {
       url.searchParams.delete('resource')
     }
-    url.hash = ''
+    if (previousActiveResourceId !== null && previousActiveResourceId !== activeResourceId) {
+      url.hash = ''
+    }
+    previousActiveResourceIdRef.current = activeResourceId ?? null
     window.history.replaceState(null, '', url.toString())
   }, [activeResourceId])

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Reviewed by Cursor Bugbot for commit eab6aed. Configure here.

@TheodoreSpeaks TheodoreSpeaks merged commit 2164cef into staging Apr 7, 2026
25 checks passed
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.

1 participant