Skip to content

feat(lit-query): add render method to query controllers#10791

Open
EskiMojo14 wants to merge 10 commits into
TanStack:mainfrom
EskiMojo14:query-render
Open

feat(lit-query): add render method to query controllers#10791
EskiMojo14 wants to merge 10 commits into
TanStack:mainfrom
EskiMojo14:query-render

Conversation

@EskiMojo14
Copy link
Copy Markdown

@EskiMojo14 EskiMojo14 commented May 25, 2026

🎯 Changes

see #10711 - adds a render method based on the query status, based on the Tasks API

  render() {
    return this.repo.render({
      pending: () => html`Loading...`
      error: (query) => html`Error: ${query.error.message}`
      success: (query) => html`
        <h1>${query.data.name}</h1>
        <p>${query.data.description}</p>
        <strong>${query.data.stargazers_count} stars</strong>
      `
    })
  }

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run 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

  • New Features

    • Added a render method to query, mutation, and infinite-query controllers for state-based rendering (pending/error/success).
  • Documentation

    • Added "Rendering" guide sections with examples for queries, mutations, and infinite queries.
  • Exports

    • Introduced typed rendering helpers to the Lit Query package for consistent renderer handling.
  • Tests

    • Added unit tests covering render behavior across statuses and edge cases.
  • Chores

    • Bumped package with a minor release entry.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 78a198b5-0da1-4f7a-859f-cb831b5b6165

📥 Commits

Reviewing files that changed from the base of the PR and between 97e932a and 65cc829.

📒 Files selected for processing (1)
  • packages/lit-query/src/render.ts

📝 Walkthrough

Walkthrough

Adds a typed rendering utility and a render convenience method to query, mutation, and infinite query controllers; wires implementations to delegate to renderResult; updates tests and documentation; and adds a changeset for a minor release bump.

Changes

Render Method Feature

Layer / File(s) Summary
Core rendering infrastructure and types
packages/lit-query/src/render.ts, packages/lit-query/src/tests/render.test.ts
Exports ResultRenderers mapped type (optional renderers per status), RendererResult conditional type (inferred return type by status), and renderResult function that selects a renderer by result.status and returns its output or undefined. Tests cover type narrowing and fallback behavior.
Query controller render method
packages/lit-query/src/createQueryController.ts, packages/lit-query/src/index.ts, packages/lit-query/src/tests/query-controller.test.ts
Adds render(renderers) to QueryResultAccessor, delegates to renderResult(controller.current, renderers), re-exports renderResult, and tests pending→success, error, and undefined-when-missing-renderer cases.
Mutation controller render method
packages/lit-query/src/createMutationController.ts, packages/lit-query/src/tests/mutation-controller.test.ts
Adds render(renderers) to MutationResultAccessor, delegates to renderResult, and tests idle→success, error, pending (deferred), and undefined-when-missing-renderer cases.
Infinite query controller render method
packages/lit-query/src/createInfiniteQueryController.ts, packages/lit-query/src/tests/infinite-and-options.test.ts
Adds render(renderers) to InfiniteQueryResultAccessor, delegates to renderResult, and tests pending→success with page data, error, and undefined-when-missing-renderer cases.
Documentation and release notes
docs/framework/lit/guides/queries.md, docs/framework/lit/guides/mutations.md, docs/framework/lit/guides/infinite-queries.md, .changeset/crisp-sloths-sneeze.md
Adds Rendering sections with Task API-style examples for pending/error/success renderers and a changeset declaring a minor bump.

🎯 3 (Moderate) | ⏱️ ~25 minutes

A rabbit's render so fine,
With pending, error, success divine,
Task API meets LitHTML's glow,
Controllers now let templates flow, 🐰✨
Query, Mutation, Infinite—all in the show!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a render method to query controllers in the lit-query package.
Description check ✅ Passed The description covers all required template sections with details about changes, a code example, completed checklist items, and release impact confirmation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/framework/lit/guides/mutations.md (1)

172-185: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Import nothing in the example snippet.

This example uses nothing (Line 179) but the imports shown in this guide only include html/LitElement, so copy-pasting the snippet can fail.

Proposed doc fix
-import { LitElement, html } from 'lit'
+import { LitElement, html, nothing } from 'lit'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/framework/lit/guides/mutations.md` around lines 172 - 185, The example
uses the special sentinel nothing in the render() example but the shown imports
only include html/LitElement; update the snippet imports to also import nothing
(e.g., from 'lit') so copy-pasting works and the pending template can return
nothing; ensure the updated example shows nothing alongside html/LitElement
imports and keep addTodo.render(...) and the pending/error/success handlers
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/lit-query/src/createMutationController.ts`:
- Line 72: Update the JSDoc in createMutationController.ts: replace the phrase
"query result" with "mutation result" in the comment for the accessor inside
createMutationController (the JSDoc that begins "/** Renders the query result
... */") so the description correctly refers to mutation results.

In `@packages/lit-query/src/createQueryController.ts`:
- Line 19: The import in createQueryController.ts incorrectly treats
RendererResult and ResultRenderers as runtime values; change the import to use
type-only qualifiers for RendererResult and ResultRenderers (e.g., import type {
RendererResult, ResultRenderers } from './render.js') while keeping renderResult
as a normal import, and apply the same type-only import change in
createMutationController.ts and createInfiniteQueryController.ts so all three
modules import those two symbols as types only.

---

Outside diff comments:
In `@docs/framework/lit/guides/mutations.md`:
- Around line 172-185: The example uses the special sentinel nothing in the
render() example but the shown imports only include html/LitElement; update the
snippet imports to also import nothing (e.g., from 'lit') so copy-pasting works
and the pending template can return nothing; ensure the updated example shows
nothing alongside html/LitElement imports and keep addTodo.render(...) and the
pending/error/success handlers unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf4f14c7-08aa-4d27-a0e7-1ce5aa4b29b2

📥 Commits

Reviewing files that changed from the base of the PR and between 514c132 and 4d2c97e.

📒 Files selected for processing (13)
  • .changeset/crisp-sloths-sneeze.md
  • docs/framework/lit/guides/infinite-queries.md
  • docs/framework/lit/guides/mutations.md
  • docs/framework/lit/guides/queries.md
  • packages/lit-query/src/createInfiniteQueryController.ts
  • packages/lit-query/src/createMutationController.ts
  • packages/lit-query/src/createQueryController.ts
  • packages/lit-query/src/index.ts
  • packages/lit-query/src/render.ts
  • packages/lit-query/src/tests/infinite-and-options.test.ts
  • packages/lit-query/src/tests/mutation-controller.test.ts
  • packages/lit-query/src/tests/query-controller.test.ts
  • packages/lit-query/src/tests/render.test.ts

Comment thread packages/lit-query/src/createMutationController.ts Outdated
Comment thread packages/lit-query/src/createQueryController.ts Outdated
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.

1 participant