Skip to content

Commit

Permalink
Move to svelte 5 $effect
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Nov 2, 2024
1 parent d5bc03f commit 48ca9a6
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/routes/(marketing)/search/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts">
import { run } from "svelte/legacy"
import { page } from "$app/stores"
import { browser } from "$app/environment"
import { onMount } from "svelte"
Expand Down Expand Up @@ -54,13 +52,13 @@
// searchQuery is $page.url.hash minus the "#" at the beginning if present
let searchQuery = $state(decodeURIComponent($page.url.hash.slice(1) ?? ""))
run(() => {
$effect(() => {
if (fuse) {
results = fuse.search(searchQuery)
}
})
// Update the URL hash when searchQuery changes so the browser can bookmark/share the search results
run(() => {
$effect(() => {
if (browser && window.location.hash.slice(1) !== searchQuery) {
goto("#" + searchQuery, { keepFocus: true })
}
Expand Down

0 comments on commit 48ca9a6

Please sign in to comment.