Skip to content

Commit 6b5ba98

Browse files
fix: Resolve SSR hydration mismatch and base path issues
- Replace onMount with for isDemo state in contact page - Fixes SSR/client hydration mismatch causing content flicker - Ensures consistent rendering between server and client - Makes state reactive to URL parameter changes during navigation - Use {base} path for banner CTA link instead of hardcoded '/contact' - Ensures compatibility with non-root deployment paths - Prevents broken links when deployed to subpaths like GitHub Pages - Maintains consistency with other site navigation Improves user experience by eliminating layout shifts and ensures robust deployment compatibility across different hosting environments.
1 parent e29b6ab commit 6b5ba98

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/routes/+layout.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import '../app.scss';
33
import { Megaphone } from 'lucide-svelte';
44
import { page } from '$app/stores';
5+
import { base } from '$app/paths';
56
67
let { children } = $props();
78
@@ -22,7 +23,7 @@
2223
<Megaphone size={18} />
2324
</span>
2425
<span class="banner-message">Context Engine is launching soon!</span>
25-
<a href="/contact?type=demo" class="banner-cta">Request Demo</a>
26+
<a href="{base}/contact?type=demo" class="banner-cta">Request Demo</a>
2627
</div>
2728
</div>
2829
</div>

src/routes/contact/+page.svelte

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,17 @@
1515
import { onMount } from 'svelte';
1616
1717
let formState: 'idle' | 'submitting' | 'success' | 'error' = $state('idle');
18-
let isDemo = $state(false);
18+
19+
// Reactive to URL changes, works with SSR and client-side navigation
20+
let isDemo = $derived($page.url.searchParams.get('type') === 'demo');
21+
1922
let formData = $state({
2023
name: '',
2124
email: '',
22-
subject: '',
25+
subject: isDemo ? 'Request Demo' : '',
2326
message: ''
2427
});
2528
26-
onMount(() => {
27-
isDemo = $page.url.searchParams.get('type') === 'demo';
28-
if (isDemo) {
29-
formData.subject = 'Request Demo';
30-
}
31-
});
32-
3329
async function handleSubmit(event: SubmitEvent) {
3430
event.preventDefault();
3531
formState = 'submitting';

0 commit comments

Comments
 (0)