Skip to content

Commit 91fd2cb

Browse files
committed
Replace history.replaceState with SvelteKit replaceState
Refactored usage of history.replaceState to use the SvelteKit-provided replaceState function in both +page.svelte files. This ensures better integration with SvelteKit's navigation and state management.
1 parent ace4173 commit 91fd2cb

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/routes/+page.svelte

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<script lang="ts">
2-
import { goto } from "$app/navigation";
2+
import { goto, replaceState } from "$app/navigation";
33
import { base } from "$app/paths";
44
import { page } from "$app/state";
55
import { usePublicConfig } from "$lib/utils/PublicConfig.svelte";
66
77
const publicConfig = usePublicConfig();
88
99
import ChatWindow from "$lib/components/chat/ChatWindow.svelte";
10-
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
11-
import { pendingMessage } from "$lib/stores/pendingMessage";
12-
import { useSettingsStore } from "$lib/stores/settings.js";
13-
import { findCurrentModel } from "$lib/utils/models";
14-
import { sanitizeUrlParam } from "$lib/utils/urlParams";
15-
import { onMount } from "svelte";
10+
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
11+
import { pendingMessage } from "$lib/stores/pendingMessage";
12+
import { useSettingsStore } from "$lib/stores/settings.js";
13+
import { findCurrentModel } from "$lib/utils/models";
14+
import { sanitizeUrlParam } from "$lib/utils/urlParams";
15+
import { onMount, tick } from "svelte";
1616
1717
let { data } = $props();
1818
@@ -82,7 +82,9 @@ import { onMount } from "svelte";
8282
void createConversation(query);
8383
const url = new URL(page.url);
8484
url.searchParams.delete("q");
85-
history.replaceState({}, "", url);
85+
tick().then(() => {
86+
replaceState(url, page.state);
87+
});
8688
return;
8789
}
8890
@@ -91,7 +93,9 @@ import { onMount } from "svelte";
9193
draft = promptQuery;
9294
const url = new URL(page.url);
9395
url.searchParams.delete("prompt");
94-
history.replaceState({}, "", url);
96+
tick().then(() => {
97+
replaceState(url, page.state);
98+
});
9599
}
96100
} catch (err) {
97101
console.error("Failed to process URL parameters:", err);

src/routes/models/[...model]/+page.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script lang="ts">
22
import { page } from "$app/state";
33
import { base } from "$app/paths";
4-
import { goto } from "$app/navigation";
5-
import { onMount } from "svelte";
4+
import { goto, replaceState } from "$app/navigation";
5+
import { onMount, tick } from "svelte";
66
import { usePublicConfig } from "$lib/utils/PublicConfig.svelte";
77
88
import ChatWindow from "$lib/components/chat/ChatWindow.svelte";
@@ -68,7 +68,9 @@
6868
void createConversation(query);
6969
const url = new URL(page.url);
7070
url.searchParams.delete("q");
71-
history.replaceState({}, "", url);
71+
tick().then(() => {
72+
replaceState(url, page.state);
73+
});
7274
return;
7375
}
7476
@@ -77,7 +79,9 @@
7779
draft = promptQuery;
7880
const url = new URL(page.url);
7981
url.searchParams.delete("prompt");
80-
history.replaceState({}, "", url);
82+
tick().then(() => {
83+
replaceState(url, page.state);
84+
});
8185
}
8286
} catch (err) {
8387
console.error("Failed to process URL parameters:", err);

0 commit comments

Comments
 (0)