app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit dc7a7e2bc2982b17dc4857c843d71897f62deb9e
parent 43f63e1d5a348ec4ac926377341b849062b9fc8a
Author: triesap <tyson@radroots.org>
Date:   Mon,  5 Oct 2026 21:05:44 +0000

web: gate search editing on client initialization (HCP-020)

- Disable server-rendered search editing and submission until hydration completes
- Preserve caller availability, raw input, query restoration and IME behavior
- Reproduce delayed-script readiness in the real loopback browser
- Verify the scoped recovery with fresh checks and independent acceptance

Diffstat:
Mweb/src/lib/components/SearchForm.svelte | 10++++++++--
Mweb/tests/e2e/query-navigation.spec.ts | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mweb/tests/unit/bootstrap.test.ts | 5++---
Mweb/tests/unit/components/search-form.test.ts | 5+++--
Mweb/tests/unit/route-inventory.test.ts | 16++++++++++++++++
5 files changed, 85 insertions(+), 7 deletions(-)

diff --git a/web/src/lib/components/SearchForm.svelte b/web/src/lib/components/SearchForm.svelte @@ -1,4 +1,5 @@ <script lang="ts"> + import { onMount } from 'svelte'; import FormField from './primitives/FormField.svelte'; import Button from './primitives/Button.svelte'; let { @@ -15,10 +16,14 @@ const id = $props.id(); let input = $derived(initialValue); let composing = $state(false); + let ready = $state(false); + onMount(() => { + ready = true; + }); const unavailable = $derived(disabled || !onsubmit); function submit(event: SubmitEvent) { event.preventDefault(); - if (!unavailable && !composing) onsubmit?.(input); + if (ready && !unavailable && !composing) onsubmit?.(input); } </script> @@ -38,6 +43,7 @@ {id} class="input textarea" rows="2" + disabled={!ready} aria-describedby={describedby} aria-invalid={invalid} value={input} @@ -57,7 +63,7 @@ label="Search" type="submit" variant="primary" - disabled={unavailable} + disabled={unavailable || !ready} /> </div> {#if unavailable} diff --git a/web/tests/e2e/query-navigation.spec.ts b/web/tests/e2e/query-navigation.spec.ts @@ -89,3 +89,59 @@ test('real search preserves rejected input and does not navigate or execute exce } expect(server.state()).toEqual({ listening: false, childProcesses: 0 }); }); + +test('search editing waits for real hydration and query restoration when scripts are delayed', async ({ + browser +}) => { + const server = await createStaticHarness(); + const context = await browser.newContext(); + const external: string[] = []; + let releaseScripts!: () => void; + const scriptsReady = new Promise<void>((resolve) => { + releaseScripts = resolve; + }); + let delayedScripts = 0; + try { + await context.route('**/*', async (route) => { + if (new URL(route.request().url()).origin !== server.url) { + external.push(route.request().url()); + return route.abort(); + } + if (new URL(route.request().url()).pathname.endsWith('.js')) { + delayedScripts++; + await scriptsReady; + } + return route.continue(); + }); + const page = await context.newPage(); + await page.goto(server.url + '/search?q=turnips', { waitUntil: 'commit' }); + const input = page.getByRole('textbox', { + name: 'What are you looking for?' + }); + const submit = page.getByRole('button', { name: 'Search', exact: true }); + await expect( + page.getByRole('heading', { name: 'Search food' }) + ).toBeVisible(); + await expect.poll(() => delayedScripts).toBeGreaterThan(0); + await expect(input).toBeDisabled(); + await expect(submit).toBeDisabled(); + releaseScripts(); + await expect(input).toBeEnabled(); + await expect(input).toHaveValue('turnips'); + await expect(submit).toBeEnabled(); + await input.fill(' CARROTS\nVICTORIA 菜 '); + await submit.click(); + await expect(page).toHaveURL( + server.url + '/search?q=carrots+victoria+%E8%8F%9C' + ); + await expect(input).toBeEnabled(); + await expect(input).toHaveValue('carrots victoria 菜'); + expect(external).toEqual([]); + } finally { + releaseScripts(); + await context.close(); + await server.close(); + } + expect(context.pages()).toHaveLength(0); + expect(server.state()).toEqual({ listening: false, childProcesses: 0 }); +}); diff --git a/web/tests/unit/bootstrap.test.ts b/web/tests/unit/bootstrap.test.ts @@ -33,9 +33,8 @@ describe('static guest shell', () => { expect(html).toContain('What are you looking for?'); expect(html).toContain('For example, carrots or carrots Victoria.'); expect(html).toContain('rows="2"'); - expect(html).not.toMatch( - /<button[^>]*type="submit"[^>]*disabled[^>]*>Search/ - ); + expect(html).toMatch(/<button[^>]*type="submit"[^>]*disabled[^>]*>Search/); + expect(html).toMatch(/<textarea[^>]*disabled/); expect(html).not.toContain('Search is unavailable during development.'); expect(html).not.toContain('<h1>'); }); diff --git a/web/tests/unit/components/search-form.test.ts b/web/tests/unit/components/search-form.test.ts @@ -39,7 +39,7 @@ describe('shared labelled search form SSR', () => { expect(html).toContain('Search is unavailable during development.'); expect(html).not.toMatch(/action=|placeholder=|maxlength=|required/); }); - it('enables an explicit typed caller without invoking it during SSR', () => { + it('retains an explicit typed caller but waits for client initialization before enabling controls', () => { const html = render(SearchForm, { props: { onsubmit: (input: string) => { @@ -47,7 +47,8 @@ describe('shared labelled search form SSR', () => { } } }).body; - expect(html).not.toMatch(/<button[^>]*disabled/); + expect(html).toMatch(/<button[^>]*disabled/); + expect(html).toMatch(/<textarea[^>]*disabled/); expect(html).not.toContain('Search is unavailable'); }); it('honors explicit disabled even with a caller', () => { diff --git a/web/tests/unit/route-inventory.test.ts b/web/tests/unit/route-inventory.test.ts @@ -1,3 +1,4 @@ +import SearchForm from '../../src/lib/components/SearchForm.svelte'; import { prerender as editPrerender } from '../../src/routes/products/[naddr=naddr]/edit/+page'; import { params } from '../../src/params'; import { readFileSync, readdirSync } from 'node:fs'; @@ -136,3 +137,18 @@ it('the pinned Kit3 consolidated matcher adapter preserves existing bounded synt await params.naddr['~standard'].validate('unsupported-coordinate') ).toHaveProperty('issues'); }); + +it('public search SSR cannot accept input or submit before client initialization', () => { + const output = render(SearchForm, { + props: { + onsubmit: () => { + throw new Error('SSR must not submit'); + } + } + }); + expect(output.body).toMatch(/<textarea[^>]*disabled/); + expect(output.body).toMatch(/<button[^>]*disabled/); + expect(output.body).not.toContain( + 'Search is unavailable during development.' + ); +});