fix: failed scrolling with comment jumping

This commit is contained in:
James Xylight committed 2025-07-25 15:42:46 -07:00
1 parent 940b7b1d0f
commit bea9e0b832
6 files changed
+34 -31

No files matched your search

@@ -16,6 +16,7 @@
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import CommentForm from './CommentForm.svelte'
import type { CommentNodeI } from './comments.svelte'
import { page } from '$app/state'
interface Props {
node: CommentNodeI
@@ -109,12 +110,7 @@
{/if}
<li
class={[
'py-3 relative',
node.comment_view.comment.distinguished &&
' text-primary-900 dark:text-primary-100 bg-green-400/5 -mx-4 sm:-mx-6 px-4 sm:px-6',
clazz,
]}
class={['py-3 relative', clazz]}
id={node.comment_view.comment.id.toString()}
>
{#if meta}
@@ -176,12 +172,21 @@
<div class={['expand max-w-full', open && 'open', contentClass]}>
<div id="comment-content">
<div
class="flex flex-col whitespace-pre-wrap
max-w-full gap-1 mt-1 relative w-full"
class={[
'flex flex-col whitespace-pre-wrap max-w-full gap-1 mt-1 relative w-full',
]}
>
<Markdown
source={node.comment_view.comment.content}
class="text-[15px] text-slate-800 dark:text-zinc-200 leading-[1.3]"
class={[
'text-[15px] text-slate-800 dark:text-zinc-200 leading-[1.3]',
node.comment_view.comment.distinguished
? 'bg-green-400/10 p-1 rounded-lg w-max font-medium'
: page.url.hash.slice(1) ==
node.comment_view.comment.id.toString() &&
'bg-slate-100 dark:bg-zinc-800 p-1 rounded-lg w-max font-medium',
]}
/>
{#if actions}
<CommentActions
@@ -50,7 +50,6 @@
{#snippet item(index)}
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
<Comments
isParent={true}
bind:nodes={() => [nodes[index]], v => (nodes[index] = v[0])}
{post}
/>
@@ -7,7 +7,6 @@
import { errorMessage } from '$lib/lemmy/error'
import type { Post } from 'lemmy-js-client'
import { Button, toast } from 'mono-svelte'
import { onMount } from 'svelte'
import { ArrowDownCircle, Icon } from 'svelte-hero-icons'
import Comment from './Comment.svelte'
import Comments from './Comments.svelte'
@@ -15,23 +14,10 @@
interface Props {
nodes: CommentNodeI[]
isParent: boolean
post: Post
}
let { nodes = $bindable(), isParent, post }: Props = $props()
let hydrated = $state(false)
onMount(() => {
hydrated = true
if (isParent && page.url.hash && browser) {
document.getElementById(page.url.hash)?.scrollIntoView({
behavior: 'smooth',
block: 'center',
})
}
})
let { nodes = $bindable(), post }: Props = $props()
let childrenPage = 0
@@ -114,12 +100,12 @@
bind:open={nodes[index].expanded}
>
{#if node.children?.length > 0}
<Comments {post} bind:nodes={nodes[index].children} isParent={false} />
<Comments {post} bind:nodes={nodes[index].children} />
{/if}
</Comment>
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
<svelte:element
this={hydrated ? 'div' : 'a'}
this={browser ? 'div' : 'a'}
class="w-full h-10 border-y-0! -mt-2 -ml-2.5"
href="/comment/{page.params.instance}/{node.comment_view.comment.id}"
>
+2 -1
View File
@@ -116,6 +116,7 @@
<script lang="ts">
import SvelteMarkdown from 'svelte-markdown'
import { setContext } from 'svelte'
import type { ClassValue } from 'svelte/elements'
interface RendererOptions {
autoloadImages: boolean
@@ -126,7 +127,7 @@
inline?: boolean
noStyle?: boolean
style?: string
class?: string
class?: ClassValue
rendererOptions?: RendererOptions
}
+1 -2
View File
@@ -18,8 +18,7 @@
class="flex flex-col gap-4 my-auto h-full justify-center max-w-md w-full mx-auto"
>
<h1
class="text-primary-900 dark:text-primary-100 text-6xl font-black flex items-center flex-row gap-2
font-display border-b pb-4 border-slate-200 dark:border-zinc-800"
class="text-primary-900 dark:text-primary-100 text-6xl font-black flex items-center flex-row gap-2 border-b pb-4 border-slate-200 dark:border-zinc-800 font-mono"
>
{page.status}
</h1>
@@ -1,4 +1,6 @@
<script lang="ts">
import { browser } from '$app/environment'
import { page } from '$app/state'
import { profile } from '$lib/auth.svelte'
import CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte'
import CommentListVirtualizer from '$lib/components/lemmy/comment/CommentListVirtualizer.svelte'
@@ -13,6 +15,7 @@
GetPostResponse,
} from 'lemmy-js-client'
import { Button, Option, Select } from 'mono-svelte'
import { onMount } from 'svelte'
import {
ArrowPath,
ArrowTrendingDown,
@@ -49,6 +52,16 @@
$effect(() => {
tree = buildCommentsTree(comments.comments)
})
onMount(() => {
if (browser && page.url.hash)
// hack because virtual list needs to calc heights
setTimeout(() => {
document
.getElementById(page.url.hash.slice(1))
?.scrollIntoView({ behavior: 'instant', block: 'center' })
}, 100)
})
</script>
{#if profile.current?.jwt}
@@ -154,7 +167,7 @@
{:else}
<div class="divide-y divide-slate-200 dark:divide-zinc-800">
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
<Comments isParent={true} nodes={tree} post={post.post_view.post} />
<Comments nodes={tree} post={post.post_view.post} />
</div>
</div>
{/if}