Repository navigation
fix(@typegpu/react): Reconfigure the canvas context when useConfigureContext options change - #3264
dchaudhari7177 wants to merge 1 commit into
Conversation
…Context options change
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
There was a problem hiding this comment.
✅ No new issues found.
( ◦°^°◦) 🏴☠️ Ahoy! I hoisted the diff aboard, charted the hooks, ran the whole fleet o' React tests (83 passin'), and gave the value-comparison logic a good keel-haulin' — she be sound, no leaks found.
Reviewed changes
useValueChangeDetectioninhelper-hooks.ts— addsvaluesEqualstructural deep-equality and a ref-based sibling ofuseChangeDetection, so a recreated options object only counts as changed when its contents differ.use-configure-context.ts— reconfigures whenrootChanged || optionsChangedat the same in-renderctxRef.current.configure(...)site, withautoResize/onResizestill split off first.- Tests — three new cases cover reconfigure on
alphaModechange (freshviewFormatseach render), no-op on value-equal options, and nestedtoneMapping.modechanges.
I traced the reconfigure paths (attach vs. root change vs. option change), confirmed valuesEqual is a correct structural equality for the plain primitive/array/object values GPUCanvasConfiguration can hold, and verified the render-phase side effect matches the pre-existing rootChanged pattern rather than introducing a new class of issue. Tests pass locally: pnpm vitest run --project=!browser packages/typegpu-react/tests/ (83 passed) and pnpm --filter @typegpu/react test:types is clean.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Fixes #3216.
Cause
useConfigureContextconfigured the context only when the canvas attached (throughroot.configureContext) or when the root changed. Its canvas options (alphaMode,colorSpace,format,toneMapping,usage,viewFormats) were read again only at those two points, so changing them after mount did nothing:Fix
helper-hooks.tsgetsuseValueChangeDetection, a sibling ofuseChangeDetectionthat compares plain objects and arrays by value. The options object,viewFormats, andtoneMappingare new references on every render, so a reference check would reconfigure on every render.useConfigureContextnow reconfigures whenrootChanged || optionsChanged, in the same place and the same way it already reconfigured for a new root.autoResizeandonResizeare split off before the comparison, as before, so changing them never reconfigures the context.Tests
Three new cases in
use-configure-context.test.tsx, in adescribethat captures the context'sconfiguremock:alphaModefrom'opaque'to'premultiplied'callsconfigureagain, with the new value and the root's device;viewFormatsarray each render) does not reconfigure;toneMapping: { mode }) reconfigures, and an equal nested object does not.Without the change to
use-configure-context.ts, the two "reconfigures" tests fail. The existing "does not reconfigure the context or the resizing on re-render" test still passes.vitest run packages/typegpu-react/tests: 83 passed.oxlint --type-awareon the package andoxfmt --checkon the changed files are clean, and so istsc --noEmitfor@typegpu/react.