fix: possible ssr leak
This commit is contained in:
1 parent
430eba300a
commit
4f92725b9e
2 files changed
+20
-10
No files matched your search
+14
-4
@@ -1,3 +1,10 @@
|
|||||||
|
<script lang="ts" context="module">
|
||||||
|
export const _posts = writable<{
|
||||||
|
data: GetPostsResponse
|
||||||
|
params: URLSearchParams
|
||||||
|
}>(undefined)
|
||||||
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||||
@@ -11,8 +18,9 @@
|
|||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import { t } from '$lib/translations.js'
|
import { t } from '$lib/translations.js'
|
||||||
import InfiniteScroll from 'svelte-infinite-scroll'
|
import InfiniteScroll from 'svelte-infinite-scroll'
|
||||||
import { _posts } from './+page.js'
|
|
||||||
import { Spinner } from 'mono-svelte'
|
import { Spinner } from 'mono-svelte'
|
||||||
|
import { writable } from 'svelte/store'
|
||||||
|
import type { GetPostsResponse } from 'lemmy-js-client'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -20,8 +28,6 @@
|
|||||||
let hasMore = data.posts.posts.length == limit
|
let hasMore = data.posts.posts.length == limit
|
||||||
|
|
||||||
async function loadMore() {
|
async function loadMore() {
|
||||||
console.log('loading more')
|
|
||||||
|
|
||||||
if (!hasMore) return
|
if (!hasMore) return
|
||||||
|
|
||||||
const newPosts = await getClient().getPosts({
|
const newPosts = await getClient().getPosts({
|
||||||
@@ -34,6 +40,8 @@
|
|||||||
|
|
||||||
hasMore = newPosts.posts.length == limit
|
hasMore = newPosts.posts.length == limit
|
||||||
|
|
||||||
|
console.log(hasMore)
|
||||||
|
|
||||||
data.cursor.next = newPosts.next_page
|
data.cursor.next = newPosts.next_page
|
||||||
data.posts.posts = [...data.posts.posts, ...newPosts.posts]
|
data.posts.posts = [...data.posts.posts, ...newPosts.posts]
|
||||||
|
|
||||||
@@ -54,6 +62,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<PostFeed posts={data.posts.posts}>
|
<PostFeed posts={data.posts.posts}>
|
||||||
|
{#if hasMore}
|
||||||
<div class="w-full flex flex-col skeleton gap-2 animate-pulse pt-6">
|
<div class="w-full flex flex-col skeleton gap-2 animate-pulse pt-6">
|
||||||
<div class="w-96 h-8"></div>
|
<div class="w-96 h-8"></div>
|
||||||
<div class="w-full h-48"></div>
|
<div class="w-full h-48"></div>
|
||||||
@@ -62,7 +71,8 @@
|
|||||||
<div class="w-24 h-8"></div>
|
<div class="w-24 h-8"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<InfiniteScroll window threshold={750} {hasMore} on:loadMore={loadMore} />
|
{/if}
|
||||||
|
<InfiniteScroll window threshold={750} on:loadMore={loadMore} />
|
||||||
</PostFeed>
|
</PostFeed>
|
||||||
<div class="mt-auto">
|
<div class="mt-auto">
|
||||||
<Pageination
|
<Pageination
|
||||||
|
|||||||
+6
-6
@@ -3,11 +3,8 @@ import { userSettings } from '$lib/settings.js'
|
|||||||
import type { GetPostsResponse, ListingType, SortType } from 'lemmy-js-client'
|
import type { GetPostsResponse, ListingType, SortType } from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
import { error } from '@sveltejs/kit'
|
import { error } from '@sveltejs/kit'
|
||||||
|
import { _posts } from './+page.svelte'
|
||||||
export const _posts = writable<{
|
import { browser } from '$app/environment'
|
||||||
data: GetPostsResponse
|
|
||||||
params: URLSearchParams
|
|
||||||
}>(undefined)
|
|
||||||
|
|
||||||
export async function load({ url, fetch }) {
|
export async function load({ url, fetch }) {
|
||||||
const cursor = url.searchParams.get('cursor') as string | undefined
|
const cursor = url.searchParams.get('cursor') as string | undefined
|
||||||
@@ -35,7 +32,10 @@ export async function load({ url, fetch }) {
|
|||||||
show_hidden: settings.posts.showHidden,
|
show_hidden: settings.posts.showHidden,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!(cached && url.searchParams.toString() == cached.params.toString()))
|
if (
|
||||||
|
!(cached && url.searchParams.toString() == cached.params.toString()) &&
|
||||||
|
browser
|
||||||
|
)
|
||||||
_posts.set({ data: posts, params: url.searchParams })
|
_posts.set({ data: posts, params: url.searchParams })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user