Skip to content

feat(hooks): async useViewModelInstanceAsync (deprecate sync hook)#305

Draft
mfazekas wants to merge 2 commits into
mainfrom
feat/viewmodel-instance-async
Draft

feat(hooks): async useViewModelInstanceAsync (deprecate sync hook)#305
mfazekas wants to merge 2 commits into
mainfrom
feat/viewmodel-instance-async

Conversation

@mfazekas

@mfazekas mfazekas commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

What

Adds useViewModelInstanceAsync, an async replacement for useViewModelInstance built on the non-deprecated *Async runtime APIs (viewModelByNameAsync, defaultArtboardViewModelAsync, createInstanceByNameAsync, createDefaultInstanceAsync, createBlankInstanceAsync).

Why

The sync hook creates instances via @deprecated APIs that access the Rive runtime on the JS thread (it ships with an eslint-disable @typescript-eslint/no-deprecated and a migration TODO). The async variant resolves off-thread and drops the deprecated path.

API

Returns a { instance, isLoading, error } discriminated union mirroring useRiveFile. Same overloads/params as the sync hook including required (throws once resolved to null; undefined while loading). Lifecycle uses useState/useEffect with a cancellation flag and callDispose on deps-change/unmount; onInit runs before the instance is exposed.

Backward compatible: the sync useViewModelInstance is marked @deprecated but kept working. Example screens migrated to the async hook (dataBind={instance} unchanged).

Verify

yarn tsc, yarn lint (0 errors), yarn jest (65 passed incl. 16 new async tests).

Note: same change is also present in #304 (which targets the experimental branch); this PR lands it on main independently.

mfazekas added 2 commits July 1, 2026 10:40
The sync useViewModelInstance creates instances via deprecated runtime
APIs that touch the Rive runtime on the JS thread. Add
useViewModelInstanceAsync built on the non-deprecated `*Async` APIs,
returning a { instance, isLoading, error } discriminated union (mirroring
useRiveFile), with cancellation/disposal on deps change + unmount and
onInit applied before the instance is exposed.

Keeps `required` parity (throws once resolved to null; undefined while
loading). The sync hook is marked @deprecated but left working for
backward compatibility. Migrates the example screens to the async hook.
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.

1 participant