Skip to content

fix(lit-query): avoid redundant function option updates#10716

Open
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:codex/10715-lit-query-stable-function-options
Open

fix(lit-query): avoid redundant function option updates#10716
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:codex/10715-lit-query-stable-function-options

Conversation

@raashish1601
Copy link
Copy Markdown

@raashish1601 raashish1601 commented May 17, 2026

🎯 Changes

Fixes #10715.

createQueryController now publishes the observer's current result after applying refreshed accessor options instead of creating a fresh optimistic result object on every Lit host update. This prevents function-style options that resolve to the same query state from scheduling redundant host updates and entering an update loop.

A regression test covers the stable function-options case, and a patch changeset is included for @tanstack/lit-query.

✅ 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).

Validation

  • corepack pnpm --dir packages/lit-query exec vitest run src/tests/query-controller.test.ts
  • corepack pnpm --dir packages/lit-query run test:lib
  • corepack pnpm --dir packages/lit-query run test:types
  • corepack pnpm --dir packages/lit-query run test:eslint
  • corepack pnpm exec prettier --check packages/lit-query/src/createQueryController.ts packages/lit-query/src/tests/query-controller.test.ts
  • corepack pnpm --dir packages/query-core run build
  • corepack pnpm --dir packages/lit-query run build:esm
  • corepack pnpm --dir packages/lit-query run build:cjs
  • corepack pnpm --dir packages/lit-query run test:build partially passed: publint --strict and attw --pack passed; the bundled smoke script hit a Windows spawn EINVAL when invoking pnpm.cmd, so I manually ran the same CommonJS TypeScript smoke flow with pnpm pack, npm install, and tsc, which passed.

I also attempted corepack pnpm run test:pr, but locally it expanded to 96 projects and failed on Windows symlink placeholder files such as root.eslint.config.js before reaching this change.

Summary by CodeRabbit

  • Bug Fixes

    • Optimized query result handling to prevent redundant host updates when accessor function options resolve to unchanged query data.
  • Tests

    • Added test coverage verifying no unnecessary updates occur when query results remain unchanged.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 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: c1ec170d-2e1f-4e2e-802b-fba5d20bf7c2

📥 Commits

Reviewing files that changed from the base of the PR and between 65b9b72 and 1ee00ae.

📒 Files selected for processing (3)
  • .changeset/lit-query-stable-function-options.md
  • packages/lit-query/src/createQueryController.ts
  • packages/lit-query/src/tests/query-controller.test.ts

📝 Walkthrough

Walkthrough

This PR fixes a crash when passing function-based options to createQueryController by changing how refreshOptions() retrieves the updated controller state. Instead of using the optimistic result from observer.setOptions(), it now uses the current result, preventing redundant host updates when resolved options are unchanged.

Changes

Function-based options stability

Layer / File(s) Summary
Options refresh state update
packages/lit-query/src/createQueryController.ts
In refreshOptions(), the controller result after observer.setOptions(options) is switched from the observer's optimistic result to its current result, preventing stale function options from triggering redundant updates.
Options stability test
packages/lit-query/src/tests/query-controller.test.ts
New test verifies that when function-based options resolve to the same values, no extra host.requestUpdate calls are triggered; uses staleTime: Infinity and confirms query state remains unchanged across update cycles.
Changeset release notes
.changeset/lit-query-stable-function-options.md
Patch-level changeset documents the behavior change for @tanstack/lit-query: avoiding redundant host updates when resolved accessor function options yield unchanged query results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A function that changed how results flow,
No more crashes when options grow,
Current states win the day,
Stale ones fade away,
Smooth updates from high to low! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main fix: avoiding redundant function option updates in lit-query, which directly addresses the core issue.
Description check ✅ Passed The PR description covers all required template sections with detailed changes, includes issue reference, checklist completion, and validation steps.
Linked Issues check ✅ Passed The code changes directly address #10715 by preventing redundant updates from function-style options, including regression test and changeset.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the function-style options issue: core logic fix, regression test, and changeset documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

@tin-serdar
Copy link
Copy Markdown

The change should also be applied in packages/lit-query/src/createInfiniteQueryController.ts.

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.

[lit-query]: options defined as a function cause page to crash

2 participants