Skip to content

fix: apply objectLimit globally across all object buckets after filtering#218

Open
colorbank wants to merge 1 commit into
tscircuit:mainfrom
colorbank:bounty/objectlimit-42
Open

fix: apply objectLimit globally across all object buckets after filtering#218
colorbank wants to merge 1 commit into
tscircuit:mainfrom
colorbank:bounty/objectlimit-42

Conversation

@colorbank
Copy link
Copy Markdown

Fixes #42

/claim #42

Problem

objectLimit was applied per-type bucket separately (via slice(-objectLimit)) inside filterAndLimit. With 8 object types, objectLimit={3} could still render up to 3 × 8 = 24 objects. The totalFilteredObjects count and the red warning were also computed from already-limited buckets, so they never correctly reflected the pre-limit total.

Reproduces on the existing fixture examples/interactive-object-limit-layer-and-step-filtering.fixture.tsx: with objectLimit={3} and 7 objects (3 rects + 3 points + 1 circle), all 7 rendered while the warning showed "Display limited to 3 objects. Received: 7." — wrong count too.

Changes

  • Rename filterAndLimitfilterOnly: removes per-type slice(-objectLimit), now just filters without capping
  • Add site/utils/applyObjectLimit.ts: pure helper that distributes a single global budget across all object buckets from the last bucket backwards (preserving last-N semantics)
  • Add limitedBuckets useMemo: applies applyObjectLimit once across all 8 filtered arrays after filtering
  • totalPreLimitObjects: correctly counts pre-limit filtered objects for the red warning
  • isLimitReached: compares totalPreLimitObjects > objectLimit so the warning accurately reflects when rendering is truncated
  • JSX: renders from limitedXxx arrays instead of filteredXxx

Tests

New tests/apply-object-limit.test.ts with 7 focused unit tests:

  • Total ≤ limit → returns buckets unchanged
  • Global cap distributes from last bucket backwards
  • Single bucket capped
  • Zero limit empties all buckets
  • Order preserved within buckets
  • Limit exactly equals total → identity
  • First buckets empty when limit fits only last buckets

Verification

npx --yes bun run build         # no TypeScript errors
npx --yes bun test tests/apply-object-limit.test.ts  # 7/7 pass
npx --yes bun x biome format --write ...  # clean

…ring

Previously objectLimit was applied per-type bucket separately (via
slice(-objectLimit)), meaning objectLimit={3} could still render up to
3*8=24 objects across all buckets.

This fix:
- Renames filterAndLimit to filterOnly (filter only, no per-type limit)
- Adds applyObjectLimit helper that distributes a global cap across all
  buckets from the last bucket backwards
- Adds limitedBuckets useMemo that applies the global limit once
- Updates totalPreLimitObjects to count pre-limit filtered objects
- Updates isLimitReached to compare totalPreLimitObjects vs objectLimit
- Updates JSX to render from limitedXxx instead of filteredXxx

Fixes tscircuit#42

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
graphics-debug Ready Ready Preview, Comment May 16, 2026 11:15pm

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option objectLimit that limits the number of objects displayed (after filters) on InteractiveGraphics

1 participant