Skip to content

Support callbacks in React#10518

Merged
jprochazk merged 5 commits into
mainfrom
jan/react-callbacks
Jul 10, 2025
Merged

Support callbacks in React#10518
jprochazk merged 5 commits into
mainfrom
jan/react-callbacks

Conversation

@jprochazk
Copy link
Copy Markdown
Member

@jprochazk jprochazk commented Jul 4, 2025

pixi run js-build-all
pixi run yarn --cwd rerun_js workspaces run pack

Produces rerun_js/web-viewer/web-viewer.tar.gz and rerun_js/web-viewer-react/web-viewer-react.tar.gz

These can be installed into e.g. https://github.com/rerun-io/web-viewer-react-example by running:

npm i # base dependencies
npm i ../rerun/rerun_js/web-viewer/web-viewer.tar.gz
npm i ../rerun/rerun_js/web-viewer-react/web-viewer-react.tar.gz

Afterwards run the example as normal. You can find the new callback props available on the WebViewer component, e.g. onPlay, onTimeUpdate, etc.

Implementation details

I felt bad about adding another layer of stuff that anyone working on events has to deal with, so this requires no effort whatsoever to maintain.

The callback prop types are generated automatically from @rerun-io/web-viewer event types. When a callback prop is registered, the prop name is transformed to the event name (remove on prefix, snake_case it), which is then directly registered on the underlying WebViewer instance. This way we don't need to maintain a list of events on the React side, it stays up to date automatically as new events are added in the non-React package.

@jprochazk jprochazk added 🕸️ web regarding running the viewer in a browser include in changelog labels Jul 4, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 4, 2025

Web viewer built successfully. If applicable, you should also test it:

  • I have tested the web viewer
Result Commit Link Manifest
e4cde28 https://rerun.io/viewer/pr/10518 +nightly +main

Note: This comment is updated whenever you push a commit.

@jprochazk jprochazk force-pushed the jan/react-callbacks branch from a45501b to 1f8f148 Compare July 7, 2025 10:25
@jprochazk jprochazk marked this pull request as ready for review July 7, 2025 10:39
@jprochazk
Copy link
Copy Markdown
Member Author

jprochazk commented Jul 7, 2025

I thought there was some kind of performance regression in the React package, but I probably just built it in debug mode 😬. Can't repro anymore, so this is ready

@jprochazk jprochazk added this to the 0.24.0 milestone Jul 7, 2025
@Wumpf Wumpf self-requested a review July 10, 2025 08:28
Copy link
Copy Markdown
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this prop name to event name transformation could be a bit brittle though, no? Sounds like we should leave a note to keep those names carefully in sync
Otherwise really nice to not have those duplicated once more!

Comment thread rerun_js/web-viewer-react/index.js Outdated
@jprochazk
Copy link
Copy Markdown
Member Author

this prop name to event name transformation could be a bit brittle though, no?

Yes, should add a note about making sure the event names are snake_cased versions of the same events on the Rust side

@jprochazk jprochazk merged commit fd0fa42 into main Jul 10, 2025
40 checks passed
@jprochazk jprochazk deleted the jan/react-callbacks branch July 10, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

include in changelog 🕸️ web regarding running the viewer in a browser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants