Fix objectLimit to cap total objects globally, not per type#212
Open
zeppnyc wants to merge 1 commit into
Open
Conversation
Previously, `filterAndLimit` applied `slice(-objectLimit)` to each
object type bucket independently (8 buckets: arrows, infiniteLines,
lines, rects, polygons, circles, texts, points), so a graph containing
N object types could display up to `N * objectLimit` objects.
This contradicted the issue spec ("limits the number of objects
displayed") and the existing "Display limited to X. Received: Y" UI
message, which already assumed a global cap.
Extract a pure `applyObjectLimit` helper that distributes the limit
across all object buckets, filling from the last bucket in render
order backwards (preserving the previous "last N" semantic from
`slice(-objectLimit)`). `totalFilteredObjects` now reports the true
pre-limit total so the `isLimitReached` indicator triggers correctly.
Refs tscircuit#42
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the
objectLimitprop onInteractiveGraphicsso it caps the total number of rendered objects, instead of capping each object type bucket independently.The bug
filterAndLimitinInteractiveGraphics.tsxappliedslice(-objectLimit)to every object type bucket separately:There are 8 buckets (
arrows,infiniteLines,lines,rects,polygons,circles,texts,points), so passingobjectLimit={3}could still render up to3 × 8 = 24objects.This contradicts both:
"Display limited to {objectLimit} objects. Received: {total}."— already assumes a single global cap.Reproduces on the existing fixture
examples/interactive-object-limit-layer-and-step-filtering.fixture.tsx: withobjectLimit={3}and 7 objects in the graph (3 rects + 3 points + 1 circle), all 7 currently render while the red indicator says"Display limited to 3 objects. Received: 7.".The fix
site/utils/applyObjectLimit.tsdistributes the limit globally across all object buckets, filling backwards from the last bucket in render order. This preserves the previous "last N" semantic fromslice(-objectLimit)— the most recently added objects survive.filterAndLimitno longer slices; the global limit is applied in a newlimitedBucketsmemo inInteractiveGraphics.tsx.totalFilteredObjectsnow reports the true pre-limit total, so theisLimitReachedindicator triggers exactly when the limit is actually capping output.limitedBucketsinstead of per-typefilteredXxxmemos.Verification
bun test→ 71 pass (62 baseline + 9 new unit tests forapplyObjectLimitcovering: no-limit, zero-limit, total-below-limit, single-bucket cap, multi-bucket budget fill, full-drop semantics, immutability, equality-to-total, and in-bucket order preservation)bun run format:check→ cleanbunx tsc --noEmit→ clean/claim #42