Skip to content

fix: Refactor useMotionValueRefCore into a dedicated file, introduc…#2204

Merged
Yradex merged 1 commit intolynx-family:mainfrom
f0rdream:motion_mini_seperation
Feb 9, 2026
Merged

fix: Refactor useMotionValueRefCore into a dedicated file, introduc…#2204
Yradex merged 1 commit intolynx-family:mainfrom
f0rdream:motion_mini_seperation

Conversation

@f0rdream
Copy link
Copy Markdown
Collaborator

@f0rdream f0rdream commented Feb 9, 2026

Refactor useMotionValueRefCore into a dedicated file, introduce a queueMicrotask polyfill for the mini package, and add dependency tests for the mini bundle.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a compilation error when using the mini motion build.
  • New Features

    • Added a lightweight polyfill to improve mini motion compatibility in environments without native microtask support.
  • Tests

    • Added tests covering mini motion polyfill behavior and dependency restrictions.
  • Chores

    • Recorded a patch release entry for the motion package and ensured the mini polyfill is included in the package metadata.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 9, 2026

🦋 Changeset detected

Latest commit: f7c0497

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lynx-js/motion Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@f0rdream f0rdream force-pushed the motion_mini_seperation branch from 291110e to 306c0a9 Compare February 9, 2026 08:08
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

Core hook logic was moved to a new useMotionValueRefCore module; mini package imports adjusted and a mini-specific queueMicrotask polyfill was added and declared as side-effectful. New tests validate dependency isolation for mini and the polyfill behavior. A changeset bumps the motion patch version.

Changes

Cohort / File(s) Summary
Changelog & Package
\.changeset/true-teeth-cry.md, packages/motion/package.json
Added a changeset recording a patch for @lynx-js/motion; added ./dist/mini/polyfill.js to sideEffects.
Hook refactor
packages/motion/src/hooks/useMotionValueRef.ts, packages/motion/src/hooks/useMotionValueRefCore.ts
Extracted core implementation to useMotionValueRefCore.ts; useMotionValueRef.ts now re-exports the core and delegates initialization.
Mini module & polyfill
packages/motion/src/mini/index.ts, packages/motion/src/mini/polyfill.ts
Updated mini import paths; added a self-invoking queueMicrotask shim that prefers lynx.queueMicrotask and falls back to Promise+setTimeout error rethrowing.
Tests
packages/motion/__tests__/dependencies.test.ts, packages/motion/__tests__/mini-polyfill.test.tsx
Added dependency-traversal test forbidding certain imports from mini; added runtime/unit tests for the mini polyfill behavior and queueMicrotask fallbacks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • colinaaa
  • Yradex

Poem

🐰 I hopped through hooks and moved their core,
A tiny shim to hush the microtask roar,
Tests peered down import paths with care,
Mini now stands lighter, patched, and aware—
✨ nibble, patch, and hop some more.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main objective of refactoring useMotionValueRefCore into a dedicated file and introducing a polyfill, which aligns with the changeset modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
packages/motion/src/mini/polyfill.ts (1)

4-4: Nit: inconsistent casing — shimQueueMicroTask vs queueMicrotask.

The standard API uses lowercase t in "microtask" (queueMicrotask), but the function name capitalizes it (MicroTask). Consider shimQueueMicrotask for consistency.

packages/motion/__tests__/mini-polyfill.test.tsx (1)

110-141: Verify the error-rethrow test timing is sufficient.

The polyfill chains .then(fn).catch(handler), so the .catch callback runs one microtask tick after fn throws. Two await Promise.resolve() calls (lines 136–137) should be enough, but if this test becomes flaky, adding a third tick or using await vi.runAllTimersAsync() (with fake timers) would be more deterministic.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@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: 1

🤖 Fix all issues with AI agents
In `@packages/motion/__tests__/dependencies.test.ts`:
- Around line 22-30: The forbidden-file check currently compares the raw import
specifier `file` against `forbiddenFile` before path resolution, allowing
bypasses (e.g. `animation/index`, `animation/index.js`); move the forbidden
check to after resolution where `filePath` is computed (the block that resolves
`file` into `filePath` in the traversal logic), and perform the comparison
against the resolved path (normalize relative to `rootDir` the same way the
error message builds). Also change the `visited` set to use the resolved
`filePath` (not the raw `file`) so visits and forbiddens are consistent, and
ensure `pathStack` entries used in the thrown error are the resolved/normalized
paths for accurate diagnostics.
🧹 Nitpick comments (3)
packages/motion/src/mini/polyfill.ts (1)

4-22: Naming inconsistency: shimQueueMicroTask vs queueMicrotask.

The function name uses capital T in MicroTask while the standard API and all other references use lowercase t (queueMicrotask). Consider renaming to shimQueueMicrotask for consistency.

packages/motion/__tests__/mini-polyfill.test.tsx (1)

9-54: Test validates no-crash but not polyfill functionality.

The test confirms the mini module doesn't throw in a main-thread environment, which is the stated goal. However, the onComplete callback (lines 26-29) doesn't capture or assert anything, so the test doesn't verify that the polyfill's queueMicrotask actually works for async scheduling. Consider adding an assertion that the animation completes (e.g., checking mv.get() equals 100 after completion) in a follow-up if deeper coverage is desired.

packages/motion/__tests__/dependencies.test.ts (1)

17-18: Consider adding an explicit expect assertion for test clarity.

The test relies solely on thrown errors for failure, which works but may trigger "no assertions" warnings depending on vitest config. A trailing expect (e.g., expect(true).toBe(true)) or importing expect and using it after check() would make the intent more explicit. Low priority.

Comment thread packages/motion/__tests__/dependencies.test.ts Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@f0rdream f0rdream force-pushed the motion_mini_seperation branch from 306c0a9 to 581eeba Compare February 9, 2026 08:19
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 9, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing f0rdream:motion_mini_seperation (f7c0497) with main (fe5e578)

Summary

✅ 63 untouched benchmarks
⏩ 3 skipped benchmarks1

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Feb 9, 2026

Web Explorer

#7565 Bundle Size — 383.74KiB (0%).

f7c0497(current) vs fe5e578 main#7562(baseline)

Bundle metrics  no changes
                 Current
#7565
     Baseline
#7562
No change  Initial JS 154.88KiB 154.88KiB
No change  Initial CSS 35.06KiB 35.06KiB
Change  Cache Invalidation 0% 40.36%
No change  Chunks 8 8
No change  Assets 8 8
No change  Modules 239 239
No change  Duplicate Modules 16 16
No change  Duplicate Code 2.99% 2.99%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#7565
     Baseline
#7562
No change  JS 252.82KiB 252.82KiB
No change  Other 95.85KiB 95.85KiB
No change  CSS 35.06KiB 35.06KiB

Bundle analysis reportBranch f0rdream:motion_mini_seperationProject dashboard


Generated by RelativeCIDocumentationReport issue

…e a `queueMicroask` polyfill for the `mini` package, and add dependency tests for the `mini` bundle.
@f0rdream f0rdream force-pushed the motion_mini_seperation branch from 581eeba to f7c0497 Compare February 9, 2026 09:00
@f0rdream f0rdream requested a review from Yradex February 9, 2026 09:19
@Yradex Yradex merged commit 82068ae into lynx-family:main Feb 9, 2026
47 checks passed
@f0rdream f0rdream deleted the motion_mini_seperation branch February 9, 2026 13:45
colinaaa pushed a commit that referenced this pull request Feb 23, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @lynx-js/motion@0.0.3

### Patch Changes

- Fix an issue that motion/mini will accidentally imports full version,
causing compiling error
([#2204](#2204))

## @lynx-js/react@0.116.3

### Patch Changes

- fix: remove `lynx.createSelectorQuery` deprecated warning in
production
([#2195](#2195))

- Add a DEV-only guard that detects MainThread flush loops caused by
re-entrant MTS handlers.
([#2159](#2159))

This typically happens when a MainThread handler (e.g. event callback or
`MainThreadRef`) performs UI mutations (like `Element.setStyleProperty`,
`setStyleProperties`, `setAttribute`, or `invoke`) that synchronously
trigger a flush which re-enters the handler again.

- Avoid DEV_ONLY_SetSnapshotEntryName on standalone lazy bundle.
([#2184](#2184))

- Add alog and trace for BTS event handlers.
([#2102](#2102))

- fix: Main thread functions cannot access properties on `this` before
hydration completes.
([#2194](#2194))

    This fixes the `cannot convert to object` error.

- Remove element api calls alog by default, and only enable it when
`__ALOG_ELEMENT_API__` is defined to `true` or environment variable
`REACT_ALOG_ELEMENT_API` is set to `true`.
([#2192](#2192))

- fix: captured variables in main thread functions within class
components do not update correctly
([#2197](#2197))

## @lynx-js/rspeedy@0.13.4

### Patch Changes

- Bump ts-blank-space v0.7.0
([#2238](#2238))

- Bump Rsbuild v1.7.3 with Rspack v1.7.5.
([#2189](#2189))

-   Updated dependencies \[]:
    -   @lynx-js/web-rsbuild-server-middleware@0.19.8

## @lynx-js/qrcode-rsbuild-plugin@0.4.5

### Patch Changes

- Only register console shortcuts when running in TTY environments
([#2202](#2202))

## @lynx-js/react-rsbuild-plugin@0.12.8

### Patch Changes

- Updated dependencies
\[[`4240138`](4240138)]:
    -   @lynx-js/react-webpack-plugin@0.7.4
    -   @lynx-js/react-alias-rsbuild-plugin@0.12.8
    -   @lynx-js/use-sync-external-store@1.5.0
    -   @lynx-js/react-refresh-webpack-plugin@0.3.4
    -   @lynx-js/template-webpack-plugin@0.10.3

## @lynx-js/testing-environment@0.1.11

### Patch Changes

- Remove element api calls alog by default, and only enable it when
`__ALOG_ELEMENT_API__` is defined to `true` or environment variable
`REACT_ALOG_ELEMENT_API` is set to `true`.
([#2192](#2192))

## @lynx-js/web-constants@0.19.8

### Patch Changes

-   Updated dependencies \[]:
    -   @lynx-js/web-worker-rpc@0.19.8

## @lynx-js/web-core@0.19.8

### Patch Changes

- fix: avoid error when LynxView is removed immediately after connected
([#2182](#2182))

-   Updated dependencies \[]:
    -   @lynx-js/web-constants@0.19.8
    -   @lynx-js/web-mainthread-apis@0.19.8
    -   @lynx-js/web-worker-rpc@0.19.8
    -   @lynx-js/web-worker-runtime@0.19.8

## @lynx-js/web-core-wasm@0.0.3

### Patch Changes

- Updated dependencies
\[[`e0972ef`](e0972ef),
[`3bc017e`](3bc017e),
[`e2d349e`](e2d349e),
[`d924b6a`](d924b6a)]:
    -   @lynx-js/web-elements@0.11.2
    -   @lynx-js/web-worker-rpc@0.19.8

## @lynx-js/web-elements@0.11.2

### Patch Changes

- Add scrollHeight/scrollWidth getters to XList.
([#2156](#2156))

- Inherit padding styles for x-input elements.
([#2199](#2199))

- Remove the default lazy-loading attribute from x-image elements.
([#2186](#2186))

- Fix x-input number type forwarding to the inner input element.
([#2193](#2193))

## @lynx-js/web-mainthread-apis@0.19.8

### Patch Changes

-   Updated dependencies \[]:
    -   @lynx-js/web-constants@0.19.8

## @lynx-js/web-worker-runtime@0.19.8

### Patch Changes

-   Updated dependencies \[]:
    -   @lynx-js/web-constants@0.19.8
    -   @lynx-js/web-mainthread-apis@0.19.8
    -   @lynx-js/web-worker-rpc@0.19.8

## @lynx-js/react-webpack-plugin@0.7.4

### Patch Changes

- Remove element api calls alog by default, and only enable it when
`__ALOG_ELEMENT_API__` is defined to `true` or environment variable
`REACT_ALOG_ELEMENT_API` is set to `true`.
([#2192](#2192))

## create-rspeedy@0.13.4



## @lynx-js/react-alias-rsbuild-plugin@0.12.8



## upgrade-rspeedy@0.13.4



## @lynx-js/web-core-server@0.19.8



## @lynx-js/web-rsbuild-server-middleware@0.19.8



## @lynx-js/web-worker-rpc@0.19.8

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants