Skip to content

Commit

Permalink
load() is re-run in SvelteKit 2
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisSpomer committed Feb 10, 2025
1 parent cd8ad33 commit 081d924
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/routes/threads/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
export let data: PageData
let id: number
let clip: boolean
let locationHashPresent: boolean
let clip: boolean = true
let lastReload: Date
$: ({ id, clip, lastReload } = data)
$: ({ id, locationHashPresent, lastReload } = data)
let thread: Thread | null = null
let isLoading: boolean = false
Expand All @@ -21,6 +22,8 @@
let replyText: string = ""
let isPosting: boolean = false
$: if (locationHashPresent && clip) clip = false
$: if (browser)
{
id
Expand Down
6 changes: 3 additions & 3 deletions src/routes/threads/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export async function load({ params }: LoadEvent): Promise<LoadOutput>
{
const { id } = params
const threadID = Number.parseInt(id, 10)
if (isNaN(threadID)) error(404, `There's no thread "${id}".`);
const clip = browser && !location.hash.match(/^#Post\d+$/)
if (isNaN(threadID)) error(404, `There's no thread "${id}".`)
const locationHashPresent = browser && !!location.hash.match(/^#Post\d+$/)

return { id: threadID, clip: clip, lastReload: new Date() }
return { id: threadID, locationHashPresent: locationHashPresent, lastReload: new Date() }
}

0 comments on commit 081d924

Please sign in to comment.