Skip to content

Add Pretext virtualized text example#1175

Open
tannerlinsley wants to merge 1 commit into
mainfrom
codex/pretext-example-docs
Open

Add Pretext virtualized text example#1175
tannerlinsley wants to merge 1 commit into
mainfrom
codex/pretext-example-docs

Conversation

@tannerlinsley
Copy link
Copy Markdown
Member

@tannerlinsley tannerlinsley commented May 25, 2026

Adds a React Pretext example, a robust usage guide, docs route validation, and all-example build verification. Verification: node scripts/verify-links.ts; node scripts/verify-examples.ts; Pretext example visual smoke via local Vite and headless Chrome.

Summary by CodeRabbit

  • New Features

    • Added a React example demonstrating text measurement and virtual scrolling integration using Pretext.
  • Documentation

    • Added comprehensive guide on integrating Pretext for text measurement with TanStack Virtual, covering installation, usage patterns, and best practices.
  • Chores

    • Added verification scripts for documentation links and example builds.

Review Change Stack

@tannerlinsley tannerlinsley requested a review from a team as a code owner May 25, 2026 20:00
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

📝 Walkthrough

Walkthrough

This PR adds a new Pretext text-measurement integration with complete documentation, a React virtualized chat example demonstrating the pattern, TypeScript configuration updates for Lit examples, and verification scripts for maintaining consistency across documentation and example builds.

Changes

Pretext Documentation, Example, and Verification Tooling

Layer / File(s) Summary
Pretext Documentation and Navigation
docs/pretext.md, docs/config.json
New doc explains when and how to use Pretext for text-based row height estimation, covering caching with prepare(), width-dependent layout, font invalidation, and robustness patterns. Navigation config adds links to the doc under Getting Started and to a new React example under Examples.
React Pretext Example Setup and Configuration
examples/react/pretext/package.json, examples/react/pretext/tsconfig.json, examples/react/pretext/vite.config.js, examples/react/pretext/README.md
Build scaffolding defines runtime/dev dependencies, dev/build/serve scripts, TypeScript with React JSX transform, Vite with React plugin, and usage instructions.
React Pretext Example Application
examples/react/pretext/index.html, examples/react/pretext/src/index.css, examples/react/pretext/src/main.tsx
Chat message example renders 2,000 virtualized rows; measures text via Pretext canvas layout or fallback heuristic; caches per-message metrics; tracks container width with ResizeObserver and re-measures on resize; clears caches and remeasures after document.fonts.ready; includes navigation buttons and render count stats.
Lit Examples TypeScript Configuration
examples/lit/dynamic/tsconfig.json, examples/lit/fixed/tsconfig.json, docs/config.json
Add explicit types: ["node"] to Lit example TypeScript configs; remove Svelte Variable example from navigation.
Documentation Link and Example Build Verification
package.json, scripts/verify-links.ts, scripts/verify-examples.ts
New npm scripts verify-links and verify-examples with dev dependencies fast-glob and markdown-link-extractor. verify-links globs docs markdown, extracts/validates relative links to existing files, parses docs/config.json, validates all to routes, and cross-checks against enumerated example directories. verify-examples discovers all examples/*/*/package.json, validates each has a build script, runs the build, and reports failures.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐰 New docs for measuring text, an example app with chat rows galore,
Pretext and Virtual spinning together, scaling what's stored.
TypeScript tidy-ups, verification scripts to keep things pure,
Two thousand messages virtualized—height estimates sound and sure! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides a high-level overview of changes but does not follow the required template structure with 'Changes' and 'Checklist' sections. Restructure the description to follow the template: add '## 🎯 Changes' section with detailed change descriptions, and complete the '✅ Checklist' and '🚀 Release Impact' sections with appropriate checkboxes.
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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a React Pretext virtualized text example, which aligns with the primary objectives of the pull request.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/pretext-example-docs
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch codex/pretext-example-docs

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/react/pretext/vite.config.js

Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): examples/react/pretext/vite.config.js


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

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
examples/react/pretext/src/main.tsx (1)

166-177: ⚡ Quick win

Conditionally access document.fonts.ready for older/quirky runtimes

In examples/react/pretext/src/main.tsx, the effect calls document.fonts.ready directly; since the Font Loading API (document.fonts / FontFaceSet.ready) is broadly “widely available” in modern browsers, this should not break typical targets. If you explicitly support older/embedded webviews where document.fonts may be missing, guard the access (e.g., only use .ready when document.fonts exists) to avoid a runtime throw.

🤖 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 `@examples/react/pretext/src/main.tsx` around lines 166 - 177, The effect
currently accesses document.fonts.ready unguarded which can throw in
older/quirky runtimes; update the React.useEffect callback to first check for
document.fonts (e.g., if (document.fonts && document.fonts.ready) { ... } else {
... }) and in the else branch run the same cleanup actions
(preparedCache.clear(), clearCache(), setFontVersion(...)) or a safe fallback;
keep the cancelled flag handling and ensure you attach the .then handler only
when document.fonts.ready exists to avoid runtime errors.
🤖 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 `@examples/react/pretext/tsconfig.json`:
- Around line 2-4: Move the "composite" setting into the "compilerOptions"
object so it becomes an effective TypeScript compiler option: remove the
top-level "composite" key and add "composite": true inside the existing
"compilerOptions" block (ensure the key name and boolean value are preserved and
do not create a duplicate "compilerOptions" object).

In `@scripts/verify-links.ts`:
- Line 235: The script currently calls verifyLinks().catch(console.error) which
logs errors but leaves the process exit code as zero; change the top-level
invocation of verifyLinks to catch errors and exit non-zero on failure (e.g.,
verifyLinks().catch(err => { console.error(err); process.exit(1); })) so any
runtime exception causes the script/CI to fail; update the invocation where
verifyLinks() is called.

---

Nitpick comments:
In `@examples/react/pretext/src/main.tsx`:
- Around line 166-177: The effect currently accesses document.fonts.ready
unguarded which can throw in older/quirky runtimes; update the React.useEffect
callback to first check for document.fonts (e.g., if (document.fonts &&
document.fonts.ready) { ... } else { ... }) and in the else branch run the same
cleanup actions (preparedCache.clear(), clearCache(), setFontVersion(...)) or a
safe fallback; keep the cancelled flag handling and ensure you attach the .then
handler only when document.fonts.ready exists to avoid runtime errors.
🪄 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: f6a1a7f7-fedd-43e1-bc6b-9f9d1b2a9a13

📥 Commits

Reviewing files that changed from the base of the PR and between 693d915 and e66500c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • docs/config.json
  • docs/pretext.md
  • examples/lit/dynamic/tsconfig.json
  • examples/lit/fixed/tsconfig.json
  • examples/react/pretext/README.md
  • examples/react/pretext/index.html
  • examples/react/pretext/package.json
  • examples/react/pretext/src/index.css
  • examples/react/pretext/src/main.tsx
  • examples/react/pretext/tsconfig.json
  • examples/react/pretext/vite.config.js
  • package.json
  • scripts/verify-examples.ts
  • scripts/verify-links.ts

Comment on lines +2 to +4
"composite": true,
"compilerOptions": {
"target": "ES2020",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In TypeScript tsconfig.json, is "composite" a valid top-level property, or must it be inside "compilerOptions"?

💡 Result:

Answer: "composite" must be inside "compilerOptions" in a tsconfig.json; it is not a valid top-level tsconfig property. TypeScript’s official TSConfig reference lists a small set of top-level properties (such as "files", "extends", "include", "exclude", and "references") and then lists "composite" under the "compilerOptions" section [1]. Therefore, writing "composite" at the top level (e.g., { "composite": true }) is not supported by the tsconfig schema; it should be written like: { "compilerOptions": { "composite": true } } The official documentation for the "composite" option also describes it as a TSConfig option (i.e., a compiler option) and ties it to project references behavior rather than treating it as a top-level tsconfig field [2].

Citations:


Move "composite" under "compilerOptions" in tsconfig

In examples/react/pretext/tsconfig.json, "composite" is not a valid top-level tsconfig property; it must be placed under "compilerOptions" to take effect.

♻️ Proposed fix
 {
-  "composite": true,
   "compilerOptions": {
+    "composite": true,
     "target": "ES2020",
     "useDefineForClassFields": true,
🤖 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 `@examples/react/pretext/tsconfig.json` around lines 2 - 4, Move the
"composite" setting into the "compilerOptions" object so it becomes an effective
TypeScript compiler option: remove the top-level "composite" key and add
"composite": true inside the existing "compilerOptions" block (ensure the key
name and boolean value are preserved and do not create a duplicate
"compilerOptions" object).

Comment thread scripts/verify-links.ts
}
}

verifyLinks().catch(console.error)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Ensure unexpected errors fail the script with a non-zero exit code.

Line 235 currently logs errors but may still exit successfully on runtime exceptions, which can produce false-green CI.

Suggested fix
-verifyLinks().catch(console.error)
+verifyLinks().catch((error) => {
+  console.error(error)
+  process.exit(1)
+})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
verifyLinks().catch(console.error)
verifyLinks().catch((error) => {
console.error(error)
process.exit(1)
})
🤖 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 `@scripts/verify-links.ts` at line 235, The script currently calls
verifyLinks().catch(console.error) which logs errors but leaves the process exit
code as zero; change the top-level invocation of verifyLinks to catch errors and
exit non-zero on failure (e.g., verifyLinks().catch(err => { console.error(err);
process.exit(1); })) so any runtime exception causes the script/CI to fail;
update the invocation where verifyLinks() is called.

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