Skip to content

docs(Autocomplete): add Live Wikipedia story demonstrating a real remote API - #382

Merged
garrity-miepub merged 2 commits into
mainfrom
docs/autocomplete-live-wiki
Aug 19, 2026
Merged

docs(Autocomplete): add Live Wikipedia story demonstrating a real remote API#382
garrity-miepub merged 2 commits into
mainfrom
docs/autocomplete-live-wiki

Conversation

@garrity-miepub

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #381. The Async Source story demonstrates the remote wiring pattern with a simulated setTimeout backend — this adds a Live Wikipedia story that hits a real third-party API, proving the pattern works cross-origin against production infrastructure and demonstrating the full production recipe.

What changed

Docs-only change to src/components/Autocomplete/Autocomplete.stories.tsx (+110):

  • New Live Wikipedia story — type-ahead against Wikipedia's opensearch endpoint (CORS-enabled via origin=*):
    • 250 ms debounce before each request
    • AbortController cancels the in-flight request per keystroke, so stale responses never land
    • Loading state via emptyMessage ("Searching Wikipedia…")
    • Selected article renders as a working external link; clearOnSelect={false} keeps the query
  • Wiring-patterns docs section cross-references the new story

Notes

  • Story requires internet access; it is not in the curated visual-regression list (tests/visual/components.spec.ts), so no snapshot flakiness
  • No component code touched

Verification

  • pnpm typecheck ✅ / eslint ✅ / prettier ✅ / pnpm vitest run src/components/Autocomplete 7/7 ✅
  • Verified live in Storybook: "electronic health rec" → debounced fetch → 8 real Wikipedia articles → selection renders link to https://en.wikipedia.org/wiki/Electronic_health_record

…ote API

Fetches Wikipedia's CORS-enabled opensearch endpoint with the
production recipe: 250ms debounce + AbortController so stale
responses never land, loading state via emptyMessage.
Cross-referenced from the wiring-patterns docs.
Copilot AI lite review requested due to automatic review settings August 19, 2026 21:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Storybook documentation example for Autocomplete that demonstrates the “remote/async items” wiring pattern against a real third-party API (Wikipedia opensearch), and cross-references it from the existing wiring guide section.

Changes:

  • Updates the “Remote / async source” docs section to reference the new “Live Wikipedia” story.
  • Adds a new LiveWikipedia story that performs debounced fetches to Wikipedia and renders a selected result as an external link.
Suppressed comments (3)

src/components/Autocomplete/Autocomplete.stories.tsx:316

  • latestQuery should be updated on every keystroke (including when clearing the input) so pending timers/fetches can reliably detect they’re stale and bail out.
  const search = (q: string) => {
    clearTimeout(debounceTimer.current);
    abortRef.current?.abort();
    if (!q) {
      setItems([]);

src/components/Autocomplete/Autocomplete.stories.tsx:336

  • Even with aborting, a stale timer/fetch can still reach this point; guard before applying results so the list never updates for an older query.
        ];
        setItems(
          titles.map((title, i) => ({

src/components/Autocomplete/Autocomplete.stories.tsx:345

  • On non-abort failures, the story currently keeps showing the previous query’s results while the input contains the new query. Clearing items (and optionally showing an error message) avoids misleading/stale results.
      } catch (err) {
        if ((err as Error).name !== 'AbortError') setLoading(false);
      }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/components/Autocomplete/Autocomplete.stories.tsx
Comment thread src/components/Autocomplete/Autocomplete.stories.tsx
Comment thread src/components/Autocomplete/Autocomplete.stories.tsx
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploying ui with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3ede059
Status: ✅  Deploy successful!
Preview URL: https://06104f03.ui-6d0.pages.dev
Branch Preview URL: https://docs-autocomplete-live-wiki.ui-6d0.pages.dev

View logs

Guard against stale responses updating state, check res.ok before
parsing, and clean up the debounce timer and in-flight request on
unmount. Addresses Copilot review on #382.
Copilot AI review requested due to automatic review settings August 19, 2026 21:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@garrity-miepub
garrity-miepub merged commit 1a07602 into main Aug 19, 2026
11 checks passed
@garrity-miepub
garrity-miepub deleted the docs/autocomplete-live-wiki branch August 19, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants