fix(mothership): fix url keeping markdown hash on resource switch#3979
fix(mothership): fix url keeping markdown hash on resource switch#3979TheodoreSpeaks merged 1 commit intostagingfrom
Conversation
PR SummaryLow Risk Overview This prevents markdown header hashes from persisting across resource switches while keeping the Reviewed by Cursor Bugbot for commit eab6aed. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR fixes a bug where the URL fragment (e.g.,
Confidence Score: 5/5This PR is safe to merge — it is a minimal, correct one-line bug fix Single-line addition of No files require special attention Important Files Changed
Sequence DiagramsequenceDiagram
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)
Reviews (1): Last reviewed commit: "fix(mothership): fix url keeping markdow..." | Re-trigger Greptile |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
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.
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.


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
Testing
Validated switching resources does not keep trailing hash
Checklist
Screenshots/Videos