fix: ssr handoff crash
This commit is contained in:
9 files changed
+98
-113
No files matched your search
@@ -3,7 +3,7 @@ import {
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js'
|
||||
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.svelte.js'
|
||||
import { client, getClient } from '$lib/lemmy.svelte.js'
|
||||
import { site } from './lemmy.svelte'
|
||||
import { instanceToURL, moveItem } from '$lib/util.svelte'
|
||||
|
||||
@@ -1,44 +1,31 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type {
|
||||
GetPostsResponse,
|
||||
ListingType,
|
||||
PostView,
|
||||
SortType,
|
||||
} from 'lemmy-js-client'
|
||||
import { Badge, Button } from 'mono-svelte'
|
||||
import {
|
||||
ArchiveBox,
|
||||
ChevronDoubleUp,
|
||||
ExclamationTriangle,
|
||||
Icon,
|
||||
Minus,
|
||||
Plus,
|
||||
} from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
import { browser } from '$app/environment'
|
||||
import { onMount, tick, type SvelteComponent } from 'svelte'
|
||||
import {
|
||||
createVirtualizer,
|
||||
createWindowVirtualizer,
|
||||
type SvelteVirtualizer,
|
||||
} from '@tanstack/svelte-virtual'
|
||||
import { afterNavigate, beforeNavigate } from '$app/navigation'
|
||||
import { combineCrossposts } from './crosspost.svelte'
|
||||
import { afterNavigate } from '$app/navigation'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { client } from '$lib/lemmy.svelte'
|
||||
import {
|
||||
postFeeds,
|
||||
type PostFeed,
|
||||
type PostFeedID,
|
||||
} from '$lib/lemmy/postfeed'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { t } from '$lib/translations'
|
||||
import { createWindowVirtualizer } from '@tanstack/svelte-virtual'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
import {
|
||||
ArchiveBox,
|
||||
ChevronDoubleUp,
|
||||
ExclamationTriangle,
|
||||
Icon,
|
||||
Plus,
|
||||
} from 'svelte-hero-icons'
|
||||
import InfiniteScroll from 'svelte-infinite-scroll'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
|
||||
let virtualItemEls: HTMLElement[] = $state([])
|
||||
let virtualListEl: HTMLElement | undefined = $state(undefined)
|
||||
@@ -181,7 +168,7 @@
|
||||
if (virtualItemEls.length)
|
||||
virtualItemEls.forEach($virtualizer.measureElement)
|
||||
})
|
||||
run(() => {
|
||||
$effect(() => {
|
||||
if (posts.length && virtualListEl)
|
||||
$virtualizer.setOptions({
|
||||
scrollMargin: virtualListEl?.offsetTop,
|
||||
@@ -193,65 +180,66 @@
|
||||
<ul
|
||||
class="flex flex-col list-none divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
>
|
||||
{#if posts?.length == 0}
|
||||
<div class="h-full grid place-items-center">
|
||||
<Placeholder
|
||||
icon={ArchiveBox}
|
||||
title="No posts"
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
style="position:relative; height: {browser
|
||||
? `${$virtualizer.getTotalSize()}px`
|
||||
: '100%'}; width: 100%;"
|
||||
bind:this={virtualListEl}
|
||||
>
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items?.[0]
|
||||
? items?.[0]?.start - $virtualizer.options.scrollMargin
|
||||
: 0}px);"
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-900"
|
||||
id="feed"
|
||||
>
|
||||
{#each items as row, index (posts[row.index]?.post.id)}
|
||||
{#if posts[row.index]}
|
||||
{@const post = posts?.[row.index]}
|
||||
<li
|
||||
bind:this={virtualItemEls[index]}
|
||||
data-index={row.index}
|
||||
style={row.index < 7 ? `--anim-delay: ${index * 100}ms` : ''}
|
||||
class="relative post-container {row.index < 7
|
||||
? 'pop-in opacity-0'
|
||||
: ''} -mx-4 sm:-mx-6 px-4 sm:px-6"
|
||||
>
|
||||
<Post
|
||||
bind:post={posts[row.index]}
|
||||
hideCommunity={community}
|
||||
view={(posts[row.index]?.post.featured_community ||
|
||||
posts[row.index]?.post.featured_local) &&
|
||||
settings.posts.compactFeatured
|
||||
? 'compact'
|
||||
: settings.view}
|
||||
class="transition-all duration-250"
|
||||
onhide={() => {
|
||||
posts = posts.toSpliced(row.index, 1)
|
||||
}}
|
||||
></Post>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
{#key posts}
|
||||
{#if posts?.length == 0}
|
||||
<div class="h-full grid place-items-center">
|
||||
<Placeholder
|
||||
icon={ArchiveBox}
|
||||
title="No posts"
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div
|
||||
style="position:relative; height: {browser
|
||||
? `${$virtualizer?.getTotalSize()}px`
|
||||
: '100%'}; width: 100%;"
|
||||
bind:this={virtualListEl}
|
||||
>
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items?.[0]
|
||||
? items?.[0]?.start - $virtualizer.options.scrollMargin
|
||||
: 0}px);"
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-900"
|
||||
id="feed"
|
||||
>
|
||||
{#each items as row, index (posts[row.index]?.post.id)}
|
||||
{#if posts[row.index]}
|
||||
<li
|
||||
bind:this={virtualItemEls[index]}
|
||||
data-index={row.index}
|
||||
style={row.index < 7 ? `--anim-delay: ${index * 100}ms` : ''}
|
||||
class="relative post-container {row.index < 7
|
||||
? 'pop-in opacity-0'
|
||||
: ''} -mx-4 sm:-mx-6 px-4 sm:px-6"
|
||||
>
|
||||
<Post
|
||||
bind:post={posts[row.index]}
|
||||
hideCommunity={community}
|
||||
view={(posts[row.index]?.post.featured_community ||
|
||||
posts[row.index]?.post.featured_local) &&
|
||||
settings.posts.compactFeatured
|
||||
? 'compact'
|
||||
: settings.view}
|
||||
class="transition-all duration-250"
|
||||
onhide={() => {
|
||||
posts = posts.toSpliced(row.index, 1)
|
||||
}}
|
||||
></Post>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/key}
|
||||
|
||||
{#if settings.infiniteScroll && browser}
|
||||
{#if error}
|
||||
|
||||
+10
-10
@@ -5,6 +5,16 @@ import { env } from '$env/dynamic/public'
|
||||
import { writable } from 'svelte/store'
|
||||
import { profile } from './auth.svelte'
|
||||
|
||||
class InstanceData {
|
||||
#instance = $derived(profile.data.instance)
|
||||
|
||||
get data() {
|
||||
return this.#instance
|
||||
}
|
||||
}
|
||||
|
||||
export let instance = new InstanceData()
|
||||
|
||||
export const LINKED_INSTANCE_URL =
|
||||
(env.PUBLIC_LOCK_TO_INSTANCE ?? 'true').toLowerCase() == 'true'
|
||||
? env.PUBLIC_INSTANCE_URL
|
||||
@@ -19,13 +29,3 @@ const getDefaultInstance = (): string => {
|
||||
}
|
||||
|
||||
export const DEFAULT_INSTANCE_URL = getDefaultInstance()
|
||||
|
||||
class InstanceData {
|
||||
#instance = $derived(profile.data.instance)
|
||||
|
||||
get data() {
|
||||
return this.#instance
|
||||
}
|
||||
}
|
||||
|
||||
export let instance = new InstanceData()
|
||||
@@ -73,7 +73,7 @@
|
||||
floatingContent(node)
|
||||
}
|
||||
|
||||
const customFloatingRef = (node: HTMLButtonElement) => {
|
||||
const customFloatingRef = (node: HTMLDivElement) => {
|
||||
const n = node.children.item(0)
|
||||
|
||||
// @ts-ignore
|
||||
@@ -102,7 +102,7 @@
|
||||
/>
|
||||
|
||||
{#if target}
|
||||
<button
|
||||
<div
|
||||
onmouseover={() => (openOnHover ? (open = true) : false)}
|
||||
onmouseleave={() => (openOnHover ? (open = false) : false)}
|
||||
onfocus={() => (openOnHover ? (open = true) : false)}
|
||||
@@ -111,14 +111,14 @@
|
||||
onkeydown={(e) => {
|
||||
if (e.key == 'Escape') open = false
|
||||
}}
|
||||
role="menu"
|
||||
type="button"
|
||||
tabindex="0"
|
||||
role="button"
|
||||
class="{canUseContents ? 'contents text-left' : 'w-max h-max'} {clazz}"
|
||||
bind:this={el}
|
||||
use:customFloatingRef
|
||||
>
|
||||
{@render target?.()}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if open}
|
||||
|
||||
Reference in new issue
Block a user