3.3 KiB
3.3 KiB
React Wrapper Notes
This directory contains the @revealjs/react wrapper. Future changes must preserve the current Reveal/React synchronization model unless the behavior is intentionally redesigned and the tests are updated to match.
Source Of Truth
- Implementation:
react/src/Deck.tsxreact/src/Slide.tsxreact/src/Fragment.tsx
- Behavioral tests:
react/src/__tests__/Deck.test.tsxreact/src/__tests__/Slide.test.tsxreact/src/__tests__/Fragment.test.tsx
- Public-facing behavior summary:
react/README.md
Deck Lifecycle Invariants
Deckcreates oneRevealinstance on mount and destroys it on unmount.Deckmust remain safe under ReactStrictMode; do not reintroduce double initialization.- Event props are wired with
deck.on()after initialization and cleaned up withdeck.off()when callbacks change or the component unmounts.
Reveal.sync() Policy
Reveal.sync()is expensive. Call it rarely.Deckmust not callsync()for ordinary React content updates inside existing slides.- Example: timers, counters, text changes, or other React-only DOM updates inside a slide should not trigger a full deck sync.
Deckshould only callsync()when the rendered slide structure changes.- Current meaning: slides added, removed, reordered, or regrouped into/out of vertical stacks.
- On first ready render, one deck-level sync is still expected.
Reveal.configure() Policy
configis shallow-compared.- Recreating the
configobject with the same values must not callconfigure(). configure()should only be called after the deck is initialized and ready.configure()performs its own Reveal-side sync, so the wrapper must avoid an immediate redundantsync()afterward.- The current code uses a skip flag for this. If you change that logic, preserve the existing behavior where the skip state is reset safely even if Reveal is briefly not ready during the follow-up render.
Slide-Level Sync Policy
Sliderenders a<section>and owns slide-level attribute syncing viadeck.syncSlide(slide).Slideshould only callsyncSlide()when the slide's effectivedata-*attribute signature changes after mount.Slidemust not callsyncSlide()on first render; the initial deck-level sync handles first-time registration.
Responsibility Split
- Keep responsibilities narrow:
Deckhandles Reveal instance lifecycle, config, plugin capture, event wiring, and structure-level sync.Slidehandles slide-local attribute mapping andsyncSlide().Stack,Code, andFragmentshould stay lightweight unless there is a strong reason otherwise.
- Avoid solving slide-local problems with deck-wide
sync()when a narrower mechanism is possible.
When Changing Behavior
- If you change sync/config/plugin behavior, update the relevant tests first or in the same change.
- If you change the public React API or behavior, update
react/README.md. - Prefer adding narrow tests for regressions:
- content-only rerenders must not trigger full deck sync
- structural slide changes must still trigger full deck sync
- slide attribute changes must trigger
syncSlide()only
Validation
Run these after React wrapper changes:
npm run react:testnpm run react:build