Skip to content

Commit

Permalink
Add remark about reading SharedValue from the js thread (#6160)
Browse files Browse the repository at this point in the history
## Summary

Reading from a shared value on the js thread may block the JS thread
until the UI runtime finishes whatever it's doing. This isn't really
communicated clearly and adding it to the docs seems like the best
option as we don't want to show warnings.

## Test plan

I asked ChatGPT to point out problems (it did).
  • Loading branch information
j-piasecki authored Jun 25, 2024
1 parent 4f1e289 commit 7aea7e5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/docs-reanimated/docs/core/useSharedValue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import SharedValueSrc from '!!raw-loader!@site/src/examples/SharedValue';

- When you change the `sv.value` Reanimated will update the styles and keep the shared value in sync between the threads. However, this won't trigger a typical React re-render because a shared value is a plain JavaScript object.

- When you read the `sv.value` on the [JavaScript thread](/docs/fundamentals/glossary#javascript-thread), the thread will get blocked until the value is fetched from the [UI thread](/docs/fundamentals/glossary#ui-thread). In most cases it will be negligible, but if the UI thread is busy or you are reading a value multiple times, the wait time needed to synchronize both threads may significantly increase.

- When you change the `sv.value` the update will happen synchronously on the [UI thread](/docs/fundamentals/glossary#ui-thread). On the other hand, on the [JavaScript thread](/docs/fundamentals/glossary#javascript-thread) the update is asynchronous. This means when you try to immediately log the `value` after the change it will log the previously stored value.

<Indent>
Expand Down

0 comments on commit 7aea7e5

Please sign in to comment.