Skip to content

fix(@typegpu/react): Reconfigure the canvas context when useConfigureContext options change - #3264

Open
dchaudhari7177 wants to merge 1 commit into
software-mansion:mainfrom
dchaudhari7177:fix/3216-reconfigure-context
Open

dchaudhari7177 wants to merge 1 commit into
software-mansion:mainfrom
dchaudhari7177:fix/3216-reconfigure-context

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

Fixes #3216.

Cause

useConfigureContext configured the context only when the canvas attached (through root.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:

const { ref } = useConfigureContext({ alphaMode: transparent ? 'premultiplied' : 'opaque' });
// re-rendering with a different `transparent` kept the first alphaMode

Fix

  • helper-hooks.ts gets useValueChangeDetection, a sibling of useChangeDetection that compares plain objects and arrays by value. The options object, viewFormats, and toneMapping are new references on every render, so a reference check would reconfigure on every render.
  • useConfigureContext now reconfigures when rootChanged || optionsChanged, in the same place and the same way it already reconfigured for a new root. autoResize and onResize are 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 a describe that captures the context's configure mock:

  • switching alphaMode from 'opaque' to 'premultiplied' calls configure again, with the new value and the root's device;
  • re-rendering with options equal by value (including a fresh viewFormats array each render) does not reconfigure;
  • a nested change (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-aware on the package and oxfmt --check on the changed files are clean, and so is tsc --noEmit for @typegpu/react.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 16:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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

  • useValueChangeDetection in helper-hooks.ts — adds valuesEqual structural deep-equality and a ref-based sibling of useChangeDetection, so a recreated options object only counts as changed when its contents differ.
  • use-configure-context.ts — reconfigures when rootChanged || optionsChanged at the same in-render ctxRef.current.configure(...) site, with autoResize/onResize still split off first.
  • Tests — three new cases cover reconfigure on alphaMode change (fresh viewFormats each render), no-op on value-equal options, and nested toneMapping.mode changes.

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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

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.

bug(@typegpu/react): useConfigureContext ignores option changes after mount

2 participants