Skip to content

Infinite Query Docs - #2390

Merged
drew-harris merged 3 commits into
mainfrom
drewh/inf-q-docs
Mar 19, 2026
Merged

Infinite Query Docs#2390
drew-harris merged 3 commits into
mainfrom
drewh/inf-q-docs

Conversation

@drew-harris

@drew-harris drew-harris commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai

coderabbitai Bot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request adds documentation infrastructure for an Infinite Queries feature. A new navigation link entry is added to the "Working with data" section, and a comprehensive documentation page is created explaining the useInfiniteQuery hook with React and Vanilla JS examples.

Changes

Cohort / File(s) Summary
Documentation and Navigation
client/www/data/docsNavigation.js, client/www/pages/docs/infinite-queries.md
Added navigation link under "Working with data" section pointing to new infinite queries documentation. Created documentation page explaining useInfiniteQuery hook, including TypeScript/React and Vanilla JS examples, reactivity semantics, and pagination behavior.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • nezaj
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding documentation for the Infinite Queries feature.
Description check ✅ Passed The description is directly related to the changeset, explaining that a user documentation page for infinite query was added with a deployed preview link.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch drewh/inf-q-docs
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@github-actions

Copy link
Copy Markdown
Contributor

View Vercel preview at instant-www-js-drewh-inf-q-docs-jsv.vercel.app.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🧹 Nitpick comments (2)
client/www/pages/docs/infinite-queries.md (2)

61-61: Simplify redundant phrase.

The phrase "returning back" is redundant; "returning" alone conveys the meaning.

✍️ Optional style improvement
-Changing any part of the query will result in a full reset of all data, returning back to a state with only one page loaded.
+Changing any part of the query will result in a full reset of all data, returning to a state with only one page loaded.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/www/pages/docs/infinite-queries.md` at line 61, Edit the sentence that
currently reads "Changing any part of the query will result in a full reset of
all data, returning back to a state with only one page loaded." and remove the
redundant word "back" so it reads "Changing any part of the query will result in
a full reset of all data, returning to a state with only one page loaded." —
update the line containing that exact sentence in infinite-queries.md.

50-50: Consider more formal verb choice.

The phrase "get created" could be replaced with "are created" for a more formal documentation tone.

✍️ Optional style improvement
-Any new posts that get created will automatically appear at the top, and as the user scrolls, the `loadNextPage` can load older posts as needed.
+Any new posts that are created will automatically appear at the top, and as the user scrolls, the `loadNextPage` can load older posts as needed.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/www/pages/docs/infinite-queries.md` at line 50, Change the informal
phrasing in the sentence containing "get created" to a more formal tense:
replace "Any new posts that get created will automatically appear at the top"
with "Any new posts that are created will automatically appear at the top" (the
sentence that also references loadNextPage for loading older posts).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@client/www/pages/docs/infinite-queries.md`:
- Line 10: Update the phrase "top level namespace" to the hyphenated form
"top-level namespace" in the sentence inside the infinite-queries.md content
(the sentence mentioning only one top level namespace is allowed) so the
compound adjective is correctly hyphenated; ensure the change appears wherever
that exact phrase occurs in the file.
- Line 8: The documentation sentence about useInfiniteQuery is incomplete:
update the description to mention that useInfiniteQuery returns not just the
list of data, canLoadNextPage, and loadNextPage, but also error and isLoading
(so it matches the example destructuring). Edit the paragraph referencing the
useInfiniteQuery hook to list all five return values (data list,
canLoadNextPage, loadNextPage, error, isLoading) and ensure the wording matches
the example shown later in the file.
- Around line 39-40: The example incorrectly calls data.map(...) even though the
query returns an object shaped like { posts: [...] }; update the rendering to
iterate over data.posts instead (e.g., use data.posts.map(post => <Post
key={post.id} post={post} />)), and add a null-safe guard (data && data.posts or
optional chaining data?.posts) to avoid runtime errors when data is undefined;
adjust the block that renders <Post key={post.id} post={post} /> accordingly.

---

Nitpick comments:
In `@client/www/pages/docs/infinite-queries.md`:
- Line 61: Edit the sentence that currently reads "Changing any part of the
query will result in a full reset of all data, returning back to a state with
only one page loaded." and remove the redundant word "back" so it reads
"Changing any part of the query will result in a full reset of all data,
returning to a state with only one page loaded." — update the line containing
that exact sentence in infinite-queries.md.
- Line 50: Change the informal phrasing in the sentence containing "get created"
to a more formal tense: replace "Any new posts that get created will
automatically appear at the top" with "Any new posts that are created will
automatically appear at the top" (the sentence that also references loadNextPage
for loading older posts).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7d2cc889-b5d1-4d6c-963e-674115cf4f3d

📥 Commits

Reviewing files that changed from the base of the PR and between d1e7c92 and 5e8add4.

📒 Files selected for processing (2)
  • client/www/data/docsNavigation.js
  • client/www/pages/docs/infinite-queries.md

Comment thread client/www/pages/docs/infinite-queries.md Outdated
Comment thread client/www/pages/docs/infinite-queries.md Outdated
Comment thread client/www/pages/docs/infinite-queries.md Outdated
Comment thread client/www/pages/docs/infinite-queries.md

@stopachka stopachka 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.

Ship it!

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

♻️ Duplicate comments (1)
client/www/pages/docs/infinite-queries.md (1)

8-8: ⚠️ Potential issue | 🟡 Minor

Clarify all returned fields from useInfiniteQuery.

Line 8 still reads as if only pagination fields are “new,” but the example on Line 20 destructures error and isLoading too. Please explicitly list all returned fields for consistency with the snippet.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/www/pages/docs/infinite-queries.md` at line 8, Update the docs text
around useInfiniteQuery to list all returned fields returned by the hook (not
just pagination ones): explicitly mention canLoadNextPage and loadNextPage plus
the standard query fields like error, isLoading (and any other fields mirrored
from useQuery) so the prose matches the example that destructures error and
isLoading; adjust the sentence that currently highlights only pagination to
enumerate these symbols (useInfiniteQuery, canLoadNextPage, loadNextPage, error,
isLoading) for clarity and consistency with the snippet.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@client/www/pages/docs/infinite-queries.md`:
- Line 58: The example query literal `{todos: {$: {limit: 20, order: createdAt:
"asc"}}}` contains malformed object syntax for the order clause; update the
example so the order parameter is a proper object (e.g., use order: {createdAt:
"asc"}) so the full example becomes a valid query object and will copy/paste
without syntax errors.
- Around line 71-85: The example uses db.subscribeInfiniteQuery with the
callback incorrectly nested inside the query object; update the call to follow
the correct signature subscribeInfiniteQuery(query, callback, opts?) by passing
the query object as the first argument and the callback (which reads
resp.data.posts and resp.canLoadNextPage) as the second argument, leaving
unsubscribe and loadNextPage destructured from the returned object; ensure the
query remains the same (posts: { $: { limit: 20, order: { createdAt: 'desc' } }
}) and that the callback is a separate parameter.

---

Duplicate comments:
In `@client/www/pages/docs/infinite-queries.md`:
- Line 8: Update the docs text around useInfiniteQuery to list all returned
fields returned by the hook (not just pagination ones): explicitly mention
canLoadNextPage and loadNextPage plus the standard query fields like error,
isLoading (and any other fields mirrored from useQuery) so the prose matches the
example that destructures error and isLoading; adjust the sentence that
currently highlights only pagination to enumerate these symbols
(useInfiniteQuery, canLoadNextPage, loadNextPage, error, isLoading) for clarity
and consistency with the snippet.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d5216f47-0e5f-4bd8-b310-ed8c0f557198

📥 Commits

Reviewing files that changed from the base of the PR and between 5e8add4 and 6b09733.

📒 Files selected for processing (1)
  • client/www/pages/docs/infinite-queries.md

Comment thread client/www/pages/docs/infinite-queries.md
Comment thread client/www/pages/docs/infinite-queries.md Outdated

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

♻️ Duplicate comments (1)
client/www/pages/docs/infinite-queries.md (1)

58-58: ⚠️ Potential issue | 🟠 Major

Fix the malformed order object in the reactivity example.

Line 58 is not valid object syntax, so this snippet cannot be copy/pasted. order needs to be an object: order: { createdAt: "asc" }.

🛠️ Proposed fix
-For example, with `{todos: {$: {limit: 20, order: createdAt: "asc"}}}` (showing oldest todos first)
+For example, with `{todos: {$: {limit: 20, order: {createdAt: "asc"}}}}` (showing oldest todos first)
#!/bin/bash
# Verify the malformed object literal in the docs example.
sed -n '56,60p' client/www/pages/docs/infinite-queries.md
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/www/pages/docs/infinite-queries.md` at line 58, The example object
literal `{todos: {$: {limit: 20, order: createdAt: "asc"}}}` is malformed;
update the `order` field to be an object by changing that snippet to `{todos:
{$: {limit: 20, order: { createdAt: "asc" }}}}` so the reactivity example is
valid and copy/pasteable—search for the `{todos: {$: {limit: 20, order:` snippet
to locate and fix it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@client/www/lib/swrCache.ts`:
- Around line 14-29: The block in swrCache.ts calling db.subscribeInfiniteQuery
(and using unsubscribe, loadNextPage and resp.data.posts) must be removed from
module scope: db is not declared, the callback assumes resp.data is present
(unsafe access to resp.data.posts) and unsubscribe is never stored/called
causing a leak; either move this snippet to a docs/example file or wrap it
behind an explicit initialization API (e.g., an initSubscribe function) that
accepts a db instance, checks the response union before accessing data,
returns/stores the unsubscribe function for proper cleanup, and ensures errors
are handled before using resp.data.posts.

In `@client/www/pages/docs/infinite-queries.md`:
- Around line 71-87: Update the Vanilla JS example for db.subscribeInfiniteQuery
to guard the discriminated union response by checking resp.error versus
resp.data before accessing resp.data.posts (e.g., handle the error case by
logging or showing resp.error.message) and demonstrate the teardown pattern by
showing how to call the captured unsubscribe function (from the const {
unsubscribe, loadNextPage } = db.subscribeInfiniteQuery(...) tuple) when
cleaning up (for example in a returned cleanup function or on window unload) so
consumers see both error handling and proper unsubscription.

---

Duplicate comments:
In `@client/www/pages/docs/infinite-queries.md`:
- Line 58: The example object literal `{todos: {$: {limit: 20, order: createdAt:
"asc"}}}` is malformed; update the `order` field to be an object by changing
that snippet to `{todos: {$: {limit: 20, order: { createdAt: "asc" }}}}` so the
reactivity example is valid and copy/pasteable—search for the `{todos: {$:
{limit: 20, order:` snippet to locate and fix it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 159d0db8-eeea-4b42-b5fe-50ea12859540

📥 Commits

Reviewing files that changed from the base of the PR and between 6b09733 and 0502a74.

📒 Files selected for processing (2)
  • client/www/lib/swrCache.ts
  • client/www/pages/docs/infinite-queries.md

Comment thread client/www/lib/swrCache.ts Outdated
Comment thread client/www/pages/docs/infinite-queries.md

@coderabbitai coderabbitai Bot 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.

♻️ Duplicate comments (2)
client/www/pages/docs/infinite-queries.md (2)

71-87: ⚠️ Potential issue | 🟠 Major

Add error handling and cleanup pattern to the example.

The callback accesses resp.data.posts without checking for resp.error, which will fail when errors occur. Additionally, while unsubscribe is captured, the documentation doesn't demonstrate when or how to call it for proper cleanup.

🛡️ Suggested enhancement
 const { unsubscribe, loadNextPage } = db.subscribeInfiniteQuery(
   {
     posts: {
       $: {
         limit: 20, // Load 20 posts at a time
         order: {
           createdAt: 'desc',
         },
       },
     },
   },
   (resp) => {
+    if (resp.error) {
+      console.error('Error:', resp.error.message);
+      return;
+    }
     console.log('Posts: ', resp.data.posts);
     console.log('Can Load More ?', resp.canLoadNextPage);
   },
 );
+
+// Clean up the subscription when no longer needed:
+// unsubscribe();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/www/pages/docs/infinite-queries.md` around lines 71 - 87, Update the
subscribeInfiniteQuery example to handle errors and demonstrate cleanup: inside
the callback passed to db.subscribeInfiniteQuery (the resp handler) check
resp.error before accessing resp.data.posts and handle/log it (early return on
error), and show calling unsubscribe (captured from const { unsubscribe,
loadNextPage }) in a cleanup pattern (e.g., in a useEffect return or on
component unmount) to avoid leaks; reference the subscribeInfiniteQuery call,
the resp parameter, and the unsubscribe identifier so readers can locate and
implement the checks and cleanup.

58-58: ⚠️ Potential issue | 🔴 Critical

Fix invalid query syntax.

The inline query has malformed JavaScript syntax. The order parameter requires an object with the field as a key, not order: createdAt: "asc".

🐛 Proposed fix
-For example, with `{todos: {$: {limit: 20, order: createdAt: "asc"}}}` (showing oldest todos first)
+For example, with `{todos: {$: {limit: 20, order: {createdAt: "asc"}}}}` (showing oldest todos first)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/www/pages/docs/infinite-queries.md` at line 58, The example inline
query `{todos: {$: {limit: 20, order: createdAt: "asc"}}}` has invalid
JavaScript for the `order` parameter; update the docs to use an object for
`order` (i.e., set `order` to an object whose key is the field name and value is
the sort direction) so the example becomes valid JavaScript—locate the example
string in the docs and replace the malformed `order: createdAt: "asc"` with the
proper object form.
🧹 Nitpick comments (1)
client/www/pages/docs/infinite-queries.md (1)

15-16: Remove unused import.

The init function is imported at line 15 but never used. The example imports db directly from "../db", which suggests db is already initialized elsewhere. Consider removing the unused import to avoid confusion.

♻️ Suggested fix
-import { init } from '@instantdb/react';
 import { db } from "../db"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/www/pages/docs/infinite-queries.md` around lines 15 - 16, Remove the
unused import of init from '@instantdb/react' since it is not referenced in this
file; keep the direct import of db (from "../db") which indicates initialization
occurs elsewhere. Locate the import statement that includes init and delete just
that import token (or the entire import line if it only imports init) so only
the necessary import of db remains, ensuring no other code paths reference init
in this module.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@client/www/pages/docs/infinite-queries.md`:
- Around line 71-87: Update the subscribeInfiniteQuery example to handle errors
and demonstrate cleanup: inside the callback passed to db.subscribeInfiniteQuery
(the resp handler) check resp.error before accessing resp.data.posts and
handle/log it (early return on error), and show calling unsubscribe (captured
from const { unsubscribe, loadNextPage }) in a cleanup pattern (e.g., in a
useEffect return or on component unmount) to avoid leaks; reference the
subscribeInfiniteQuery call, the resp parameter, and the unsubscribe identifier
so readers can locate and implement the checks and cleanup.
- Line 58: The example inline query `{todos: {$: {limit: 20, order: createdAt:
"asc"}}}` has invalid JavaScript for the `order` parameter; update the docs to
use an object for `order` (i.e., set `order` to an object whose key is the field
name and value is the sort direction) so the example becomes valid
JavaScript—locate the example string in the docs and replace the malformed
`order: createdAt: "asc"` with the proper object form.

---

Nitpick comments:
In `@client/www/pages/docs/infinite-queries.md`:
- Around line 15-16: Remove the unused import of init from '@instantdb/react'
since it is not referenced in this file; keep the direct import of db (from
"../db") which indicates initialization occurs elsewhere. Locate the import
statement that includes init and delete just that import token (or the entire
import line if it only imports init) so only the necessary import of db remains,
ensuring no other code paths reference init in this module.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f19a2a1f-8fbd-4b76-8ffb-4c0810f45c78

📥 Commits

Reviewing files that changed from the base of the PR and between 0502a74 and eed0dcc.

📒 Files selected for processing (1)
  • client/www/pages/docs/infinite-queries.md

@drew-harris
drew-harris merged commit b229af1 into main Mar 19, 2026
28 checks passed
@drew-harris
drew-harris deleted the drewh/inf-q-docs branch March 19, 2026 22:38
@coderabbitai coderabbitai Bot mentioned this pull request Aug 7, 2026
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