Skip to content

Commit 85ef23a

Browse files
committed
fix(app): don't interfere with scroll when using message nav
1 parent 3b46f90 commit 85ef23a

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

packages/app/src/pages/session.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export default function Page() {
168168
const prompt = usePrompt()
169169
const permission = usePermission()
170170
const [pendingMessage, setPendingMessage] = createSignal<string | undefined>(undefined)
171+
const [pendingHash, setPendingHash] = createSignal<string | undefined>(undefined)
171172
const sessionKey = createMemo(() => `${params.dir}${params.id ? "/" + params.id : ""}`)
172173
const tabs = createMemo(() => layout.tabs(sessionKey()))
173174
const view = createMemo(() => layout.view(sessionKey()))
@@ -1036,6 +1037,7 @@ export default function Page() {
10361037
const applyHash = (behavior: ScrollBehavior) => {
10371038
const hash = window.location.hash.slice(1)
10381039
if (!hash) {
1040+
setPendingHash(undefined)
10391041
autoScroll.forceScrollToBottom()
10401042
return
10411043
}
@@ -1044,21 +1046,25 @@ export default function Page() {
10441046
if (match) {
10451047
const msg = visibleUserMessages().find((m) => m.id === match[1])
10461048
if (msg) {
1049+
setPendingHash(undefined)
10471050
scrollToMessage(msg, behavior)
10481051
return
10491052
}
10501053

10511054
// If we have a message hash but the message isn't loaded/rendered yet,
10521055
// don't fall back to "bottom". We'll retry once messages arrive.
1056+
setPendingHash(match[1])
10531057
return
10541058
}
10551059

10561060
const target = document.getElementById(hash)
10571061
if (target) {
1062+
setPendingHash(undefined)
10581063
scrollToElement(target, behavior)
10591064
return
10601065
}
10611066

1067+
setPendingHash(undefined)
10621068
autoScroll.forceScrollToBottom()
10631069
}
10641070

@@ -1116,20 +1122,14 @@ export default function Page() {
11161122
visibleUserMessages().length
11171123
store.turnStart
11181124

1119-
const targetId =
1120-
pendingMessage() ??
1121-
(() => {
1122-
const hash = window.location.hash.slice(1)
1123-
const match = hash.match(/^message-(.+)$/)
1124-
if (!match) return undefined
1125-
return match[1]
1126-
})()
1125+
const targetId = pendingMessage() ?? pendingHash()
11271126
if (!targetId) return
11281127
if (store.messageId === targetId) return
11291128

11301129
const msg = visibleUserMessages().find((m) => m.id === targetId)
11311130
if (!msg) return
11321131
if (pendingMessage() === targetId) setPendingMessage(undefined)
1132+
if (pendingHash() === targetId) setPendingHash(undefined)
11331133
requestAnimationFrame(() => scrollToMessage(msg, "auto"))
11341134
})
11351135

0 commit comments

Comments
 (0)