feat(react): Add useGlobalViewModelInstance hook and support underlying semantics options from the JS runtime#432
Merged
Merged
Conversation
…ng semantics options from the JS runtime
zplata
requested review from
bodymovin,
Copilot and
damzobridge
and removed request for
bodymovin and
damzobridge
July 24, 2026 15:20
There was a problem hiding this comment.
Pull request overview
Adds a new React hook for binding global view model instances and introduces a small bind coalescing utility so multiple hook-driven instance registrations in the same React commit result in a single rive.bind().
Changes:
- Add
useGlobalViewModelInstancehook and export it from the public entrypoint. - Introduce
scheduleBind(microtask-based bind coalescing) and a sharedresolveViewModelInstancehelper to centralize instance selection. - Add Jest tests for the new hook/scheduler and add Storybook examples (including semantics options usage); bump
@rive-app/*runtime deps to2.39.1.
Reviewed changes
Copilot reviewed 16 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/useViewModelInstance.test.tsx | Adds coverage that main-instance binding schedules a coalesced bind. |
| test/useGlobalViewModelInstance.test.tsx | Adds resolution + registration/bind scheduling tests for the new global hook. |
| test/bindScheduler.test.tsx | Verifies bind coalescing semantics and per-Rive-instance isolation. |
| src/types.ts | Introduces UseGlobalViewModelInstanceParameters type for the new hook API. |
| src/resolveViewModelInstance.ts | Adds shared instance resolution helper used by main/global instance hooks. |
| src/index.ts | Exports useGlobalViewModelInstance from the package entrypoint. |
| src/hooks/useViewModelInstance.ts | Switches binding implementation to setViewModelInstance + scheduleBind and reuses the shared resolver. |
| src/hooks/useGlobalViewModelInstance.ts | Implements the new global view model instance hook. |
| src/bindScheduler.ts | Adds bind coalescing scheduler (scheduleBind) using a WeakSet + microtask. |
| package.json | Bumps @rive-app/canvas, @rive-app/canvas-lite, @rive-app/webgl2 to 2.39.1. |
| package-lock.json | Lockfile update for the bumped @rive-app/* dependencies. |
| examples/src/components/Semantics.tsx | Adds a semantics-focused example using semanticsMode / semanticsOptions. |
| examples/src/components/Semantics.stories.ts | Registers the Semantics example in Storybook. |
| examples/src/components/DataBindingPreRender.tsx | Adds example showing pre-render setup of main + global instances via onRiveReady + bind(). |
| examples/src/components/DataBindingPreRender.stories.ts | Registers the pre-render globals example in Storybook. |
| examples/src/components/DataBindingHooks.tsx | Adds example showing main + global binding via hooks with autoBind: false. |
| examples/src/components/DataBindingHooks.stories.ts | Registers the hooks-based globals example in Storybook. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bodymovin
reviewed
Jul 24, 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.
Adds a new hook similar to our existing
useViewModelInstancehook, for globals:useGlobalViewModelInstance.Since these hooks run independently without a convenient way to control bind(), addressing this by creating a "bind scheduler" per Rive instance that schedules a bind once per React commit and dedupes other bind schedules that happen in the same frame. For example, the following would yield best case, one bind() instead of multiple.
This keeps the declarative approach users expect with
useViewModelInstance()while keeping bind() down as much as we can.This also supports underlying semantics feature through the JS API, no changes needed at this React layer for now.