Skip to content

refactor(@typegpu/react): Use common.attachAutoResizer in useConfigureContext - #3226

Draft
iwoplaza wants to merge 9 commits into
feat/resize-commonfrom
feat/react-use-auto-resizer
Draft

iwoplaza wants to merge 9 commits into
feat/resize-commonfrom
feat/react-use-auto-resizer

Conversation

@iwoplaza

Copy link
Copy Markdown
Collaborator

Stacked on #2534.

Changes

  • The browser variant of useConfigureContext now uses common.attachAutoResizer instead of its own ResizeObserver + devicePixelRatio logic, so the resizing behavior is shared with non-React usage. The shared logic in core/use-configure-context.ts and the React Native resizer are untouched.
  • As a result, the React hook now also:
    • clamps the canvas resolution to device.limits.maxTextureDimension2D,
    • observes with box: 'device-pixel-content-box' when supported.
  • Added maxTextureDimension2D to the mocked device limits in typegpu-testing-utility (it was missing, which made the clamping produce a 0×0 canvas in tests).

Notes

  • @typegpu/react depends on typegpu via workspace:^, and common.attachAutoResizer is new, so the minimum typegpu version required by @typegpu/react needs to be bumped on release.

@iwoplaza
iwoplaza added this pull request to stack #3227 October 20, 2026 12:38
@github-actions

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@d72e9617e40bcf31915c068be64074ad93da18db
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@d72e9617e40bcf31915c068be64074ad93da18db
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@d72e9617e40bcf31915c068be64074ad93da18db

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Resolution Time Benchmark

---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [1.11, 2.27, 4.86, 7.05, 8.32, 14.37, 27.76, 29.46]
  line [1.11, 2.28, 4.83, 7.16, 8.84, 14.51, 26.60, 27.83]
  line [1.05, 2.14, 4.94, 7.21, 8.82, 13.45, 26.07, 26.61]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.31, 0.57, 0.81, 0.93, 1.28, 1.31, 1.65, 1.83]
  line [0.33, 0.56, 0.79, 0.94, 1.35, 1.23, 1.50, 1.70]
  line [0.37, 0.62, 0.79, 0.93, 1.27, 1.27, 1.49, 1.73]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [1.00, 2.63, 4.57, 8.13, 14.82, 31.84, 64.16, 129.50]
  line [1.02, 2.35, 3.77, 7.62, 13.53, 28.92, 62.77, 123.85]
  line [0.95, 2.30, 4.20, 7.68, 14.00, 28.86, 60.76, 123.21]
Loading

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased ➖ Unchanged 🔴 Increased (max 1.28%) ❔ Unknown
0 353 2 1

import * as ... in PR vs import * as ... in target (did bundle size increase?):

Test tsdown
STATIC_common.ts 56.83 kB ($${\color{red}+1.3\%}$$)
common_attachAutoResizer.ts 722 B

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

- Make attachAutoResizer more robust (rounding, contentBoxSize shapes,
  observe() without options, roots without a WebGPU device)
- Use explicit closing tags for <canvas> and <video>
- Keep the 1:1 aspect ratio in bitonic-sort and sdf-docs-examples
- Remove the resizer from log-test
- Use integer sizes and destroy stale textures in ripple-cube
- Forward onResize from the Jelly Slider landing example, and make it
  required for landing examples
- Only recreate blur textures in background-segmentation when the video
  frame size changes
@iwoplaza
iwoplaza force-pushed the feat/react-use-auto-resizer branch from d72e961 to dd1a149 Compare October 21, 2026 15:32

This branch has not been deployed

No deployments
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.

1 participant