fix(ShaderView): resize drawing buffer on layout change (rotation) - #21
Merged
Conversation
The drawing buffer was sized and the context configured exactly once at setup, so after a rotation/layout change the buffer kept its original dimensions and the shader rendered stretched / wrong-aspect. useWGPUSetup now exposes onCanvasLayout, wired to <Canvas onLayout>, which recomputes the physical-pixel size (clientSize * PixelRatio) and reconfigures the surface when it actually changes. The render loop reads canvas.width/height each frame, so the resolution uniform picks up the new size on the next frame. Sizes are rounded to integers for consistent pixel dimensions; redundant reconfigures (same size) are skipped.
blazejkustra
changed the base branch from
fix/rn-webgpu-worklets-high-bugs
to
main
June 28, 2026 12:38
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
Medium-severity fix from the worklets/WebGPU audit: no resize / rotation handling.
The drawing buffer was sized and
context.configurecalled exactly once at setup. After a rotation or any layout change, the buffer kept its original dimensions → the shader rendered stretched / wrong-aspect.Change
useWGPUSetupnow exposesonCanvasLayout, wired to<Canvas onLayout>inShaderView(composed with any consumer-providedonLayout).layoutSize * PixelRatio.get()), updatescanvas.width/height, and reconfigures the surface — but only when the size actually changed (redundant same-size passes are skipped).canvas.width/heightevery frame, so theresolutionuniform picks up the new size on the next frame.Stack
This is PR 1 of 3 for the medium audit items, based on
fix/rn-webgpu-worklets-high-bugs(PR #20):Verification
yarn typecheck✅yarn lint(changed files) ✅Note on cross-thread reconfigure
configure()runs on the JS thread while the render loop runs on the worklet runtime. Reconfigure is infrequent (rotation only) and mirrors the existing initial-configure-on-main pattern; a brief race window is possible but low-risk and is made safe once the error-handling PR (next in the stack) lands.