fix: guard bar animates against null from#296
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the @visactor/vstory-animate custom bar animations (BarBounce, BarLeap) against null/partial rect inputs coming from the animation pipeline, and wires up Jest config + unit tests to ensure these cases run in CI.
Changes:
- Added shared bar-rect helpers (
normalizeBarRect,isVerticalBarRect,createCollapsedBarRect) to provide safe fallback geometry. - Updated
BarBounce/BarLeapconstructors to acceptnullinputs and use normalized rects. - Enabled package-level Jest config and added targeted unit tests for null/partial rect scenarios.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
packages/vstory-animate/src/customAnimates/bar-utils.ts |
Introduces bar rect normalization + orientation helpers used by bar animations. |
packages/vstory-animate/src/customAnimates/bar-leap.ts |
Uses normalized rects and allows from/to to be null to avoid crashes. |
packages/vstory-animate/src/customAnimates/bar-bounce.ts |
Switches to normalized geometry + collapsed start rect to avoid null/undefined access. |
packages/vstory-animate/jest.config.js |
Switches to shared Jest base config and ensures mocks are loaded for this package. |
packages/vstory-animate/__tests__/unit/index.test.ts |
Adds unit tests covering the reported null/partial rect crash cases. |
Comments suppressed due to low confidence (1)
packages/vstory-animate/src/customAnimates/bar-bounce.ts:56
BarBounce.onUpdatebranches onto.y1 != null, butthis.tois now produced bynormalizeBarRect(...), which always sets a numericy1. That makes the horizontal branch unreachable and will prevent horizontal bars from animating correctly. Persist theverticalboolean computed from the raw inputs (before normalization) onto the instance (e.g.,this.vertical) and branch on that inonUpdateinstead of checkingto.y1.
if (to.y1 != null) {
out.y = from.y! + (to.y! - from.y!) * r1;
const height = to.y1! - to.y!;
const dh = height * r2;
out.y1 = Math.min(out.y + dh, this.to.y1!);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
xuefei1313
approved these changes
Apr 8, 2026
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
BarBounceandBarLeapagainstnull/partial rect inputs from the animation pipelineBarBounce(null, ...),y1 = 0, and horizontalBarLeapwithoutx1ts-jestconfig for@visactor/vstory-animateso these tests run in hooks/CITesting
pnpm --dir packages/vstory-animate exec jest __tests__/unit/index.test.ts --runInBandpnpm --dir packages/vstory-animate exec tsc --noEmit -p tsconfig.jsongit push -u origin issue-293-bar-animate-null-from(pre-pushranrush test --only tag:packagesuccessfully)Closes #293