-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Feat lit-query: add initial lit-query package #10501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chughgaurav
wants to merge
18
commits into
TanStack:main
Choose a base branch
from
chughgaurav:feature/lit-query-adapter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fbd1ddb
feat lit-query: add initial lit-query package
bf31fc5
remove internal docs from initial PR
a322b9c
fix review issues
d545bf7
align scripts with monorepo Nx targets and use workspace:* for query…
a87a875
feat(lit-query): fix type inference and monorepo integration
35e3ec0
fix(lit-query): polish package validation and examples
3c33376
Merge branch 'main' into feature/lit-query-adapter
TkDodo 1e98c04
ci: apply automated fixes
autofix-ci[bot] e93e740
lit-query: preserve provider handshake ordering in BaseController
2dc7432
Update .changeset/lemon-memes-divide.md
chughgaurav aee2808
removing prettier config from adapter, so that global config from the…
e976ddc
removed the package local format scripts so formatting stays centrali…
915ba27
removing like other adapters keep build and test:build as separate ta…
45acd10
Compared against the other adapters and removed the lit-query-only al…
d912e37
package:check has been removed. The CJS smoke check is still needed b…
54add68
fix(lit-query): align lit examples and integration with monorepo conv…
099c508
chore(lit-query): clean up stale package checks
a1a9868
fix(lit-query): address review feedback for lit examples and lifecycl…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/lit-query': minor | ||
| --- | ||
|
|
||
| Add initial @tanstack/lit-query package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ yarn.lock | |
| build | ||
| coverage | ||
| dist | ||
| dist-cjs | ||
| dist-ts | ||
|
|
||
| # misc | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Example | ||
|
|
||
| To run this example from the repo root: | ||
|
|
||
| - `pnpm --dir examples/lit/basic run dev` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Lit Query Basic Example</title> | ||
| </head> | ||
| <body> | ||
| <basic-query-root></basic-query-root> | ||
| <script type="module" src="/src/basic-query.ts"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const DEMO_PORT: number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| const DEFAULT_DEMO_PORT = 4173 | ||
| const envPort = process.env.DEMO_PORT | ||
|
|
||
| function resolvePort() { | ||
| if (!envPort) { | ||
| return DEFAULT_DEMO_PORT | ||
| } | ||
|
|
||
| const parsedPort = Number.parseInt(envPort, 10) | ||
| const isValidPort = | ||
| Number.isInteger(parsedPort) && parsedPort > 0 && parsedPort <= 65535 | ||
|
|
||
| if (!isValidPort) { | ||
| throw new Error( | ||
| `Invalid DEMO_PORT "${envPort}". Expected an integer between 1 and 65535.`, | ||
| ) | ||
| } | ||
|
|
||
| return parsedPort | ||
| } | ||
|
|
||
| export const DEMO_PORT = resolvePort() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>TanStack Lit Query E2E Demo</title> | ||
| </head> | ||
| <body> | ||
| <demo-root></demo-root> | ||
| <script type="module" src="/src/main.ts"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>TanStack Lit Query Lifecycle Contract Fixture</title> | ||
| </head> | ||
| <body> | ||
| <lifecycle-contract-root></lifecycle-contract-root> | ||
| <script type="module" src="/src/lifecycle-contract.ts"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Lit Query Mutation Example</title> | ||
| </head> | ||
| <body> | ||
| <mutation-example-root></mutation-example-root> | ||
| <script type="module" src="/src/mutation.ts"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "name": "@tanstack/query-example-lit-basic", | ||
| "private": true, | ||
| "version": "0.0.1", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "tsc --noEmit && vite build", | ||
| "preview": "vite preview" | ||
| }, | ||
| "dependencies": { | ||
| "@tanstack/lit-query": "^0.1.0", | ||
| "@tanstack/query-core": "^5.99.0", | ||
| "lit": "^3.3.1" | ||
| }, | ||
| "devDependencies": { | ||
| "typescript": "5.8.3", | ||
| "vite": "^6.4.1" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { html, LitElement } from 'lit' | ||
| import { QueryClient } from '@tanstack/query-core' | ||
| import { QueryClientProvider, createQueryController } from '@tanstack/lit-query' | ||
| import { | ||
| fetchTodosFromServer, | ||
| resetTodoApi, | ||
| type TodosResponse, | ||
| } from './todoApi' | ||
|
|
||
| resetTodoApi() | ||
|
|
||
| const queryClient = new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { retry: false }, | ||
| }, | ||
| }) | ||
|
|
||
| class BasicQueryProvider extends QueryClientProvider { | ||
| constructor() { | ||
| super() | ||
| this.client = queryClient | ||
| } | ||
|
|
||
| protected override createRenderRoot(): HTMLElement | DocumentFragment { | ||
| return this | ||
| } | ||
| } | ||
|
|
||
| customElements.define('basic-query-provider', BasicQueryProvider) | ||
|
|
||
| class BasicQueryExample extends LitElement { | ||
| private readonly todos = createQueryController<TodosResponse, Error>(this, { | ||
| queryKey: ['todos'], | ||
| queryFn: fetchTodosFromServer, | ||
| }) | ||
|
|
||
| protected override createRenderRoot(): HTMLElement | DocumentFragment { | ||
| return this | ||
| } | ||
|
|
||
| render() { | ||
| const query = this.todos() | ||
| return html` | ||
| <main> | ||
| <h1>Basic Query Example</h1> | ||
| <p data-testid="basic-query-status"> | ||
| Status: <strong>${query.status}</strong> | ||
| </p> | ||
| <button | ||
| data-testid="basic-refetch" | ||
| @click=${() => this.todos.refetch()} | ||
| > | ||
| Refetch | ||
| </button> | ||
|
|
||
| ${query.isPending | ||
| ? html`<p data-testid="basic-loading">Loading...</p>` | ||
| : null} | ||
| ${query.isError | ||
| ? html`<p data-testid="basic-error">Error: ${String(query.error)}</p>` | ||
| : null} | ||
|
|
||
| <ul data-testid="basic-todo-list"> | ||
| ${(query.data?.items ?? []).map( | ||
| (todo) => | ||
| html`<li data-testid="basic-todo-item">${todo.title}</li>`, | ||
| )} | ||
| </ul> | ||
| </main> | ||
| ` | ||
| } | ||
| } | ||
|
|
||
| customElements.define('basic-query-example', BasicQueryExample) | ||
|
|
||
| class BasicQueryRoot extends LitElement { | ||
| protected override createRenderRoot(): HTMLElement | DocumentFragment { | ||
| return this | ||
| } | ||
|
|
||
| render() { | ||
| return html` | ||
| <basic-query-provider> | ||
| <basic-query-example></basic-query-example> | ||
| </basic-query-provider> | ||
| ` | ||
| } | ||
| } | ||
|
|
||
| customElements.define('basic-query-root', BasicQueryRoot) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
In JavaScript, does Number.parseInt("4173abc", 10) return 4173, and what is the recommended strict validation pattern for environment variable ports?💡 Result:
Yes, Number.parseInt("4173abc", 10) returns 4173. This is because parseInt parses until it encounters a non-digit character in the specified radix (base 10 here), ignoring trailing invalid characters. The recommended strict validation pattern for environment variable ports in Node.js combines parsing with validation to ensure the entire string consists only of valid digits (no trailing junk, decimals, etc.) and the value is in the valid port range (typically 0-65535, often >0 and <=65535 for TCP ports). A common pattern, seen in Express generator's normalizePort and various best practices: function normalizePort(val) { const port = parseInt(val, 10); if (isNaN(port)) return val; // Allow named pipes if (port >= 0) return port; return false; } For stricter integer-only validation (rejecting anything not purely digits): - Test if the string matches /^\d+$/ (optionally allowing leading + or - if needed, but ports are unsigned). - Then parseInt and check range. Example strict port parser: function parseStrictPort(str) { if (!/^\d+$/.test(str)) return NaN; const port = Number.parseInt(str, 10); return (port >= 0 && port <= 65535) ? port : NaN; } Usage: const port = parseStrictPort(process.env.PORT); if (isNaN(port)) { throw new Error('Invalid PORT'); }
Citations:
🏁 Script executed:
Repository: TanStack/query
Length of output: 649
Use strict numeric validation for
DEMO_PORT.Lines 9-12 currently accept values like
"4173abc"becauseNumber.parseIntis prefix-tolerant, silently accepting invalid environment input. Enforce digit-only validation before parsing.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents