refactor(scroll): clean up debug overlay and pass anchor by param

Removes the temporary on-screen scroll diagnosis panel and the global
window.__scrollAtClick stash. The anchor scrollTop is now captured
synchronously at addStackedNote entry and threaded through
scrollToFocusedNote and scrollToNoteElement to scrollToElement, so no
state survives across calls — nothing to reset on repo or page change.
This commit is contained in:
Julien Calixte
2026-05-04 23:02:12 +02:00
parent a526a9f6af
commit 84803c45dd
3 changed files with 16 additions and 61 deletions

View File

@@ -13,7 +13,6 @@ const { isATProtoReady } = useATProtoLogin()
<new-version />
</div>
<pre id="scroll-debug"></pre>
</template>
<style lang="scss">
@@ -46,23 +45,4 @@ const { isATProtoReady } = useATProtoLogin()
::view-transition-new(remanso-logo) {
object-fit: contain;
}
#scroll-debug {
position: fixed;
bottom: 0;
left: 0;
z-index: 9999;
margin: 0;
padding: 4px 6px;
background: rgba(0, 0, 0, 0.75);
color: #fff;
font: 10px/1.3 ui-monospace, monospace;
white-space: pre;
pointer-events: none;
max-width: 100vw;
}
#scroll-debug:empty {
display: none;
}
</style>

View File

@@ -40,42 +40,14 @@ export const useOverlay = (listen = true) => {
}, 80)
}
const scrollToElement = (element: HTMLElement) => {
const scrollToElement = (element: HTMLElement, anchorTop?: number) => {
const mainApp = document.getElementById("main-app")
const clickTop = (window as unknown as { __scrollAtClick?: number })
.__scrollAtClick
if (mainApp && clickTop !== undefined) {
mainApp.scrollTop = clickTop
if (mainApp && anchorTop !== undefined) {
mainApp.scrollTop = anchorTop
}
requestAnimationFrame(() => {
const debug = document.getElementById("scroll-debug")
if (debug && mainApp) {
const er = element.getBoundingClientRect()
const cr = mainApp.getBoundingClientRect()
const lines = [
`clickTop: ${clickTop ?? "n/a"}`,
`before scrollTop: ${mainApp.scrollTop}`,
`mainApp scrollH: ${mainApp.scrollHeight} clientH: ${mainApp.clientHeight}`,
`body scrollY: ${window.scrollY} innerH: ${window.innerHeight}`,
`el.rect.top: ${er.top.toFixed(1)}`,
`mainApp.rect.top: ${cr.top.toFixed(1)}`,
`target: ${(er.top - cr.top + mainApp.scrollTop).toFixed(1)}`
]
debug.textContent = lines.join("\n")
element.scrollIntoView({ behavior: "smooth", block: "start" })
requestAnimationFrame(() => {
debug.textContent += `\nafter1f scrollTop: ${mainApp.scrollTop}`
setTimeout(() => {
debug.textContent += `\nafter500ms scrollTop: ${mainApp.scrollTop}`
}, 500)
})
} else {
element.scrollIntoView({ behavior: "smooth", block: "start" })
}
element.scrollIntoView({ behavior: "smooth", block: "start" })
})
}

View File

@@ -50,6 +50,7 @@ export const useRouteQueryStackedNotes = () => {
const scrollToNoteElement = (
cleanNoteId: string,
index: number,
anchorTop?: number,
attempts = 30
) => {
const element = document.querySelector(
@@ -57,7 +58,7 @@ export const useRouteQueryStackedNotes = () => {
) as HTMLElement | null
if (element) {
scrollToElement(element)
scrollToElement(element, anchorTop)
return
}
@@ -67,7 +68,7 @@ export const useRouteQueryStackedNotes = () => {
}
requestAnimationFrame(() => {
scrollToNoteElement(cleanNoteId, index, attempts - 1)
scrollToNoteElement(cleanNoteId, index, anchorTop, attempts - 1)
})
}
@@ -76,20 +77,22 @@ export const useRouteQueryStackedNotes = () => {
notes?: string[]
hash?: string
smoothHash?: boolean
anchorTop?: number
}
const scrollToFocusedNote = ({
noteId = null,
notes = stackedNotes.value,
hash,
smoothHash = false
smoothHash = false,
anchorTop
}: ScrollToFocusedNoteOptions = {}) => {
nextTick(() => {
const index = noteId ? notes.findIndex((nid) => nid === noteId) : 0
if (isMobile.value) {
if (noteId) {
scrollToNoteElement(noteId.replaceAll(":", "-"), index)
scrollToNoteElement(noteId.replaceAll(":", "-"), index, anchorTop)
} else {
scrollToNote(0)
}
@@ -114,15 +117,15 @@ export const useRouteQueryStackedNotes = () => {
selector?: string,
hash?: string
) => {
const mainAppEl = document.getElementById("main-app")
;(window as unknown as { __scrollAtClick?: number }).__scrollAtClick =
mainAppEl?.scrollTop ?? 0
const anchorTop =
document.getElementById("main-app")?.scrollTop ?? undefined
if (stackedNotes.value.includes(sha)) {
scrollToFocusedNote({
noteId: selector ?? sha,
hash,
smoothHash: true
smoothHash: true,
anchorTop
})
return
}
@@ -143,7 +146,7 @@ export const useRouteQueryStackedNotes = () => {
stackedNotes.value = newStackedNotes
}
scrollToFocusedNote({ noteId: selector ?? sha, hash })
scrollToFocusedNote({ noteId: selector ?? sha, hash, anchorTop })
}
return {