Skip to content

fix: guard bar animates against null from#296

Merged
xile611 merged 1 commit intodevelopfrom
issue-293-bar-animate-null-from
Apr 8, 2026
Merged

fix: guard bar animates against null from#296
xile611 merged 1 commit intodevelopfrom
issue-293-bar-animate-null-from

Conversation

@xile611
Copy link
Copy Markdown
Contributor

@xile611 xile611 commented Apr 7, 2026

Summary

  • guard BarBounce and BarLeap against null/partial rect inputs from the animation pipeline
  • normalize bar rect geometry so horizontal and vertical bars both have safe fallback coordinates and sizes
  • add targeted tests for BarBounce(null, ...), y1 = 0, and horizontal BarLeap without x1
  • enable package-level ts-jest config for @visactor/vstory-animate so these tests run in hooks/CI

Testing

  • pnpm --dir packages/vstory-animate exec jest __tests__/unit/index.test.ts --runInBand
  • pnpm --dir packages/vstory-animate exec tsc --noEmit -p tsconfig.json
  • git push -u origin issue-293-bar-animate-null-from (pre-push ran rush test --only tag:package successfully)

Closes #293

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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/BarLeap constructors to accept null inputs 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.onUpdate branches on to.y1 != null, but this.to is now produced by normalizeBarRect(...), which always sets a numeric y1. That makes the horizontal branch unreachable and will prevent horizontal bars from animating correctly. Persist the vertical boolean computed from the raw inputs (before normalization) onto the instance (e.g., this.vertical) and branch on that in onUpdate instead of checking to.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.

@xile611 xile611 merged commit b3fd38c into develop Apr 8, 2026
9 of 11 checks passed
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.

Bug: BarBounce/BarLeap animation crashes when from parameter is null

3 participants