Skip to content

fix(react): stabilize WebGPU device switching - #10506

Merged
ibgreen merged 3 commits into
masterfrom
codex/fix-react-webgpu-switching
Aug 2, 2026
Merged

ibgreen merged 3 commits into
masterfrom
codex/fix-react-webgpu-switching

Conversation

@ibgreen

@ibgreen ibgreen commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Goal

Make React device switching reliable and understandable without introducing a second WebGPU render loop or changing existing WebGL behavior.

Render lifecycle

_customRender remains the single source of truth for both backends:

  1. Deck calls _customRender whenever its layers or viewport need a redraw.
  2. If the viewport changed, the callback schedules the React update that keeps basemaps and other children synchronized.
  3. WebGL preserves the existing behavior: React updates its children first, then its layout effect redraws Deck.
  4. WebGPU redraws during the same animation frame because the current canvas texture cannot safely be saved for a later React layout effect.
  5. React children are not mounted against a detached WebGPU canvas's temporary 1 × 1 viewport; the next resize schedules the final-sized update.

There are no duplicate render or viewport synchronization paths in onViewStateChange or onAfterRender.

Device switching and canvas ownership

  • Only examples that expose device tabs receive the shared device; unsupported demos retain their existing WebGL behavior.
  • Unmount the current example while the requested device initializes so two Deck instances cannot contend for one canvas.
  • Remount the example by device identity to give each backend a clean Deck lifecycle.
  • Reuse one device-creation promise per backend; discard rejected promises so device initialization can be retried.
  • Ignore stale asynchronous switch completions; the user's latest tab selection always wins.
  • Create device-owned canvases in a detached container because the next React wrapper does not yet exist during a switch.
  • Hide a reused canvas until its replacement Deck renders its first frame, and restore its visibility if initialization is interrupted.
  • Explain each non-obvious lifecycle and canvas-ownership boundary with inline comments.
  • Remove the unrelated webpack/source-map change from the PR.

Validation

  • yarn build — passed.
  • yarn lint — passed; only pre-existing repository warnings.
  • yarn test-headless test/modules/react/deckgl.spec.ts test/modules/website/device-store.spec.ts — 11 passed, including an actual headless WebGPU adapter.
  • Commit-hook Node smoke tests — 21 passed.

@ibgreen
ibgreen requested a review from Pessimistress July 28, 2026 16:13
@coveralls

coveralls commented Jul 28, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 83.148% (+0.05%) from 83.103% — codex/fix-react-webgpu-switching into master

Comment thread modules/react/src/deckgl.ts Resolved
@ibgreen-openai ibgreen-openai mentioned this pull request Jul 30, 2026
42 of 61 tasks
Comment thread modules/react/src/deckgl.ts Resolved
Comment thread modules/react/src/deckgl.ts Resolved
@ibgreen
ibgreen merged commit a8393a5 into master Aug 2, 2026
5 checks passed
@ibgreen
ibgreen deleted the codex/fix-react-webgpu-switching branch August 2, 2026 17:49
@chrisgervang chrisgervang added this to the v9.4 milestone Aug 11, 2026
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.

5 participants