Skip to content
Source
Sign inSign up
TanStack/query

chore: update svelte examples and tests from runes PR #9692

Mergedlachlancollinsmerged 1 commit intomain fromrefs/pull/9692/headmerged by lachlancollins View on GitHub

lachlancollinscommented

🎯 Changes

Takes some of the changes from the svelte runes adapter branch and applies them here

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Documentation

    • Corrected Devtools option type to primitive boolean across React, Solid, Svelte, and Vue docs.
    • Updated Svelte reactivity examples to use a relative /api/data endpoint.
  • Chores

    • Svelte examples now use relative API paths; add mutation encodes parameters; header shows current interval; SSR layout simplified to synchronous load.
  • Style

    • Removed extraneous comments/blank lines in Svelte example configs; minor formatting cleanups.
  • Tests

    • Adjusted Svelte Query tests and fixtures to match updated UI output and defaults.
    1. ⚠️ No Changeset found

      Latest commit: 8f45f04866e50106e4085d78a255f020d6a5d75e

      Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

      This PR includes no changesets

      When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

      Click here to learn what changesets are, and how to add one.

      Click here if you're a maintainer who wants to add a changeset to this PR

    2. Walkthrough

      Documentation updates change initialIsOpen type annotations from Boolean to boolean across frameworks. Svelte docs/examples switch API endpoints to relative paths. Several Svelte example configs have comment/whitespace cleanup. One SSR load function becomes synchronous. Tests adjust output and expectations for mutation failure reason and mutation state rendering.

      Changes

      Cohort / File(s)Summary
      Docs: Devtools type annotation (Boolean → boolean)
      docs/framework/react/devtools.md, docs/framework/solid/devtools.md, docs/framework/svelte/devtools.md, docs/framework/vue/devtools.md
      Update initialIsOpen type from Boolean to boolean in docs; no runtime/control-flow changes.
      Docs: Svelte reactivity endpoint
      docs/framework/svelte/reactivity.md
      Replace fetch target from hardcoded http://localhost:5173/... to relative /api/data; remove local endpoint constant where applicable.
      Examples: Svelte endpoint and UI tweaks
      examples/svelte/auto-refetching/src/routes/+page.svelte, examples/svelte/optimistic-updates/src/routes/+page.svelte, examples/svelte/ssr/src/routes/+layout.ts, examples/svelte/star-wars/src/routes/+page.svelte, examples/svelte/optimistic-updates/src/routes/api/data/+server.ts
      Use relative API paths; encode query param in add mutation; dynamic header text; make SSR load sync (remove async); minor formatting; change array type syntax (Todo[] → Array).
      Examples: Svelte config whitespace/comments cleanup
      examples/svelte/auto-refetching/svelte.config.js, examples/svelte/basic/svelte.config.js, examples/svelte/optimistic-updates/svelte.config.js, examples/svelte/playground/svelte.config.js, examples/svelte/simple/svelte.config.js, examples/svelte/ssr/svelte.config.js, examples/svelte/star-wars/svelte.config.js
      Remove comment lines and extra blank lines; no behavioral/config changes.
      Tests: createMutation failure display
      packages/svelte-query/tests/createMutation/FailureExample.svelte, packages/svelte-query/tests/createMutation/createMutation.test.ts
      UI: show raw failureCount; change failureReason fallback to 'undefined'. Tests updated to expect "undefined" for failure reason.
      Tests: useMutationState UI and expectations
      packages/svelte-query/tests/useMutationState/BaseExample.svelte, packages/svelte-query/tests/useMutationState/useMutationState.test.ts
      Replace reactive derived display with inline JSON of statuses; add Success/Error buttons. Tests now click by role and assert "Data: [...]" strings, including filtered cases.

      Sequence Diagram(s)

      sequenceDiagram
        autonumber
        participant User as User
        participant SvelteSSR as +layout.ts (SSR)
        participant QueryClient as QueryClient
      
        User->>SvelteSSR: Request page
        Note over SvelteSSR: Synchronous load() returns data
        SvelteSSR->>QueryClient: new QueryClient()
        SvelteSSR-->>User: { queryClient }

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~25 minutes

      • TanStack/query#9630 — Touches the same Svelte test component (FailureExample.svelte); likely related adjustments to displayed fields/object shorthand in createMutation tests.

      Suggested labels

      package: svelte-query, documentation

      Poem

      A nibble of docs, a hop through tests, I twitch my whiskers at boolean quests. Endpoints now near, no localhost fear, SSR sprints—sync speed, so clear. Mutations confess what they’ve undefined, Carrots counted, states aligned. Thump! Release time—changes refined.

      Pre-merge checks and finishing touches

      ❌ Failed checks (2 warnings)
      Check nameStatusExplanationResolution
      Title Check⚠️ WarningThe title only mentions updating Svelte examples and tests from a “runes PR,” which is a vague internal reference that does not convey specific changes to other frameworks or documentation. It omits significant documentation updates such as type annotation changes across multiple framework docs and endpoint adjustments in the Svelte reactivity guide. As a result, it fails to capture the full scope and primary purpose of the changeset.Please update the title to succinctly reflect the main changes made in this pull request, including documentation type annotation updates and endpoint standardizations alongside Svelte examples and tests. Remove the ambiguous “runes PR” reference to improve clarity. A more descriptive title will help teammates quickly understand the scope of the changes without scanning the full diff.
      Description Check⚠️ WarningAlthough the pull request description follows the required template, the “## 🎯 Changes” section is overly generic and does not detail which modifications are applied or the motivation behind them. It simply states that changes from the Svelte runes adapter branch are included without specifying the actual updates. This lack of specificity makes it difficult for reviewers to understand the scope of the changes at a glance.Please expand the “## 🎯 Changes” section to include a clear summary of the specific updates such as boolean type annotation adjustments in documentation, fetch endpoint standardization, Svelte example refactoring, and test expectation updates. Briefly explain the motivation for each change to give reviewers context. This will ensure the description is informative and adheres to the repository’s contribution guidelines.
      ✅ Passed checks (1 passed)
      Check nameStatusExplanation
      Docstring Coverage✅ PassedNo functions found in the changes. Docstring coverage check skipped.
      ✨ Finishing touches
      • 📝 Generate Docstrings
        🧪 Generate unit tests
      • Create PR with unit tests
      • Post copyable unit tests in a comment
      • Commit unit tests in branch `tweak-svelte-tests`

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    3. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: svelte-query

    4. View your CI Pipeline Execution ↗ for commit 8f45f04866e50106e4085d78a255f020d6a5d75e

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded42sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded1sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-09-26 12:48:04 UTC

    5. More templates

      @tanstack/angular-query-experimental

      npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9692

      @tanstack/eslint-plugin-query

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9692

      @tanstack/query-async-storage-persister

      npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9692

      @tanstack/query-broadcast-client-experimental

      npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9692

      @tanstack/query-core

      npm i https://pkg.pr.new/@tanstack/query-core@9692

      @tanstack/query-devtools

      npm i https://pkg.pr.new/@tanstack/query-devtools@9692

      @tanstack/query-persist-client-core

      npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9692

      @tanstack/query-sync-storage-persister

      npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9692

      @tanstack/react-query

      npm i https://pkg.pr.new/@tanstack/react-query@9692

      @tanstack/react-query-devtools

      npm i https://pkg.pr.new/@tanstack/react-query-devtools@9692

      @tanstack/react-query-next-experimental

      npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9692

      @tanstack/react-query-persist-client

      npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9692

      @tanstack/solid-query

      npm i https://pkg.pr.new/@tanstack/solid-query@9692

      @tanstack/solid-query-devtools

      npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9692

      @tanstack/solid-query-persist-client

      npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9692

      @tanstack/svelte-query

      npm i https://pkg.pr.new/@tanstack/svelte-query@9692

      @tanstack/svelte-query-devtools

      npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9692

      @tanstack/svelte-query-persist-client

      npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9692

      @tanstack/vue-query

      npm i https://pkg.pr.new/@tanstack/vue-query@9692

      @tanstack/vue-query-devtools

      npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9692

      commit: 8f45f04

    6. Sizes for commit 8f45f04866e50106e4085d78a255f020d6a5d75e:

      BranchBundle Size
      Main
      This PR
    7. Codecov Report

      :white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 89.20%. Comparing base (db60bdd) to head (8f45f04). :warning: Report is 1 commits behind head on main.

      Additional details and impacted files

      Impacted file tree graph

      @@             Coverage Diff             @@
      ##             main    #9692       +/-   ##
      ===========================================
      + Coverage   46.38%   89.20%   +42.82%     
      ===========================================
        Files         214       18      -196     
        Lines        8488      176     -8312     
        Branches     1927       31     -1896     
      ===========================================
      - Hits         3937      157     -3780     
      + Misses       4108       18     -4090     
      + Partials      443        1      -442     
      ComponentsCoverage Δ
      @tanstack/angular-query-experimental∅ <ø> (∅)
      @tanstack/eslint-plugin-query∅ <ø> (∅)
      @tanstack/query-async-storage-persister∅ <ø> (∅)
      @tanstack/query-broadcast-client-experimental∅ <ø> (∅)
      @tanstack/query-codemods∅ <ø> (∅)
      @tanstack/query-core∅ <ø> (∅)
      @tanstack/query-devtools∅ <ø> (∅)
      @tanstack/query-persist-client-core∅ <ø> (∅)
      @tanstack/query-sync-storage-persister∅ <ø> (∅)
      @tanstack/query-test-utils∅ <ø> (∅)
      @tanstack/react-query∅ <ø> (∅)
      @tanstack/react-query-devtools∅ <ø> (∅)
      @tanstack/react-query-next-experimental∅ <ø> (∅)
      @tanstack/react-query-persist-client∅ <ø> (∅)
      @tanstack/solid-query∅ <ø> (∅)
      @tanstack/solid-query-devtools∅ <ø> (∅)
      @tanstack/solid-query-persist-client∅ <ø> (∅)
      @tanstack/svelte-query87.58% <ø> (ø)
      @tanstack/svelte-query-devtools∅ <ø> (∅)
      @tanstack/svelte-query-persist-client100.00% <ø> (ø)
      @tanstack/vue-query∅ <ø> (∅)
      @tanstack/vue-query-devtools∅ <ø> (∅)
      :rocket: New features to boost your workflow:
      • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
      • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
  • Actionable comments posted: 0

    🧹 Nitpick comments (5)
    packages/svelte-query/tests/useMutationState/BaseExample.svelte (2)

    26-27: Confirm calling mutate on the store value ($store) vs the store object

    Typical Svelte Query usage is successMutation.mutate() (no $), while $successMutation is usually the state value. If methods are exposed on the store object (not the value), the current calls might fail. If intentional in this branch, ignore; otherwise, prefer the non-$ form to avoid unnecessary subscriptions in handlers.

    Apply if appropriate:

    -<button on:click={() => $successMutation.mutate()}>Success</button>
    -<button on:click={() => $errorMutation.mutate()}>Error</button>
    +<button on:click={() => successMutation.mutate()}>Success</button>
    +<button on:click={() => errorMutation.mutate()}>Error</button>

    29-31: Stabilize selector surface for tests (optional)

    Relying on the literal "Data: ..." string couples tests to UI copy. Consider a test id to decouple formatting.

    -<div>
    -  Data: {JSON.stringify($mutationState.map((state) => state.status))}
    -</div>
    +<div data-testid="mutation-state">
    +  {JSON.stringify($mutationState.map((state) => state.status))}
    +</div>

    If adopted, update tests to assert via getByTestId('mutation-state').

    packages/svelte-query/tests/useMutationState/useMutationState.test.ts (3)

    36-45: Good a11y query upgrade; consider async assertions to reduce flakiness

    Switch to getByRole is solid. For DOM updates driven by timers and promises, findByText is more robust than getByText.

    -expect(rendered.getByText('Data: ["success"]')).toBeInTheDocument()
    +await rendered.findByText('Data: ["success"]')
    ...
    -expect(rendered.getByText('Data: ["success","error"]')).toBeInTheDocument()
    +await rendered.findByText('Data: ["success","error"]')

    Also, verify that the ordering from useMutationState is deterministic so the array order assertion won’t flake.


    71-80: Filter test reads well; prefer async query for stability

    Use findByText to await DOM updates post timers.

    -expect(rendered.getByText('Data: []')).toBeInTheDocument()
    +await rendered.findByText('Data: []')
    ...
    -expect(rendered.getByText('Data: ["error"]')).toBeInTheDocument()
    +await rendered.findByText('Data: ["error"]')

    106-115: Key-filter test is clear; use async assertions

    Same async assertion tweak to avoid timing flakes.

    -expect(rendered.getByText('Data: ["success"]')).toBeInTheDocument()
    +await rendered.findByText('Data: ["success"]')
    ...
    -expect(rendered.getByText('Data: ["success"]')).toBeInTheDocument()
    +await rendered.findByText('Data: ["success"]')
    📜 Review details

    Configuration used: CodeRabbit UI

    Review profile: CHILL

    Plan: Pro

    📥 Commits

    Reviewing files that changed from the base of the PR and between db60bddc961df287b4ea4d628c84fe27b07fbbff and 8f45f04866e50106e4085d78a255f020d6a5d75e.

    📒 Files selected for processing (21)
    • docs/framework/react/devtools.md (1 hunks)
    • docs/framework/solid/devtools.md (1 hunks)
    • docs/framework/svelte/devtools.md (1 hunks)
    • docs/framework/svelte/reactivity.md (2 hunks)
    • docs/framework/vue/devtools.md (1 hunks)
    • examples/svelte/auto-refetching/src/routes/+page.svelte (3 hunks)
    • examples/svelte/auto-refetching/svelte.config.js (0 hunks)
    • examples/svelte/basic/svelte.config.js (0 hunks)
    • examples/svelte/optimistic-updates/src/routes/+page.svelte (1 hunks)
    • examples/svelte/optimistic-updates/src/routes/api/data/+server.ts (1 hunks)
    • examples/svelte/optimistic-updates/svelte.config.js (0 hunks)
    • examples/svelte/playground/svelte.config.js (0 hunks)
    • examples/svelte/simple/svelte.config.js (0 hunks)
    • examples/svelte/ssr/src/routes/+layout.ts (1 hunks)
    • examples/svelte/ssr/svelte.config.js (0 hunks)
    • examples/svelte/star-wars/src/routes/+page.svelte (1 hunks)
    • examples/svelte/star-wars/svelte.config.js (0 hunks)
    • packages/svelte-query/tests/createMutation/FailureExample.svelte (1 hunks)
    • packages/svelte-query/tests/createMutation/createMutation.test.ts (1 hunks)
    • packages/svelte-query/tests/useMutationState/BaseExample.svelte (1 hunks)
    • packages/svelte-query/tests/useMutationState/useMutationState.test.ts (3 hunks)
    💤 Files with no reviewable changes (7)
    • examples/svelte/star-wars/svelte.config.js
    • examples/svelte/optimistic-updates/svelte.config.js
    • examples/svelte/playground/svelte.config.js
    • examples/svelte/simple/svelte.config.js
    • examples/svelte/ssr/svelte.config.js
    • examples/svelte/basic/svelte.config.js
    • examples/svelte/auto-refetching/svelte.config.js
    ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
    • GitHub Check: Preview
    • GitHub Check: Test
    🔇 Additional comments (12)
    examples/svelte/star-wars/src/routes/+page.svelte (1)

    5-5: Formatting tweak looks good

    Inline closing parenthesis improves readability without altering behavior.

    examples/svelte/ssr/src/routes/+layout.ts (1)

    5-16: Synchronous load is appropriate here.

    Dropping async keeps the signature valid and avoids needless promise wrapping since the body does not await anything.

    docs/framework/solid/devtools.md (1)

    71-71: Primitive boolean matches TS conventions

    Good call switching the docs to the lowercase primitive type; it aligns with TypeScript usage and the other framework docs.

    docs/framework/react/devtools.md (1)

    77-77: Consistent primitive type annotation

    The lowercase boolean is the correct TypeScript primitive and keeps this options list consistent across the docs.

    docs/framework/vue/devtools.md (1)

    64-64: Vue docs now mirror the TS primitive

    Thanks for updating this to boolean; it matches the actual prop typing and the rest of the documentation.

    docs/framework/svelte/devtools.md (1)

    64-64: Svelte options reflect the right boolean type

    Lowercase boolean is the right primitive and keeps parity with the other framework docs.

    examples/svelte/optimistic-updates/src/routes/api/data/+server.ts (1)

    9-9: Type alias tweak looks good

    Array<Todo> maintains identical semantics to the previous Todo[], so no runtime impact. 👍

    examples/svelte/optimistic-updates/src/routes/+page.svelte (1)

    23-37: Relative endpoint improves portability

    Switching to the relative /api/data keeps local/dev parity while avoiding hard-coded hostnames. All fetching logic still lines up with the server route.

    packages/svelte-query/tests/createMutation/createMutation.test.ts (1)

    89-97: Expectation aligns with updated fallback rendering

    FailureExample.svelte now renders the nullish failure reason as the literal string undefined, so this revised assertion keeps the test in sync with the component output.

    packages/svelte-query/tests/createMutation/FailureExample.svelte (1)

    22-23: Rendering tweak matches mutation state semantics

    Displaying the raw failureCount and falling back to the string 'undefined' for a nullish failureReason mirrors TanStack Query’s mutation state, so the UI now reflects the state machine more precisely and stays consistent with the updated test.

    examples/svelte/auto-refetching/src/routes/+page.svelte (1)

    23-26: Great call hardening the mutation URL.

    Using encodeURIComponent before interpolating user input into the fetch query string prevents accidental breakage (and avoids surprise characters in the request). Nicely done keeping the rest of the chain untouched.

    docs/framework/svelte/reactivity.md (1)

    18-39: Docs update looks solid.

    Switching the snippets to the shared /api/data endpoint keeps the walkthrough aligned with the updated example and avoids localhost-only assumptions.

  • lachlancollins merged this89be189

  • lachlancollins closed this

  • Sign in to join this conversation.