feat(hooks): async useViewModelInstanceAsync (deprecate sync hook)#305
Draft
mfazekas wants to merge 2 commits into
Draft
feat(hooks): async useViewModelInstanceAsync (deprecate sync hook)#305mfazekas wants to merge 2 commits into
mfazekas wants to merge 2 commits into
Conversation
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.
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.
What
Adds
useViewModelInstanceAsync, an async replacement foruseViewModelInstancebuilt on the non-deprecated*Asyncruntime APIs (viewModelByNameAsync,defaultArtboardViewModelAsync,createInstanceByNameAsync,createDefaultInstanceAsync,createBlankInstanceAsync).Why
The sync hook creates instances via
@deprecatedAPIs that access the Rive runtime on the JS thread (it ships with aneslint-disable @typescript-eslint/no-deprecatedand a migration TODO). The async variant resolves off-thread and drops the deprecated path.API
Returns a
{ instance, isLoading, error }discriminated union mirroringuseRiveFile. Same overloads/params as the sync hook includingrequired(throws once resolved tonull;undefinedwhile loading). Lifecycle usesuseState/useEffectwith a cancellation flag andcallDisposeon deps-change/unmount;onInitruns before the instance is exposed.Backward compatible: the sync
useViewModelInstanceis marked@deprecatedbut 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.