Skip to content

fix(@typegpu/react): Return value if fulfilled and not previously suspended - #3017

Open
iwoplaza wants to merge 2 commits into
mainfrom
fix/react-return-value-if-fulfilled
Open

iwoplaza wants to merge 2 commits into
mainfrom
fix/react-return-value-if-fulfilled

Conversation

@iwoplaza

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

pkg.pr.new

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

https://pkg.pr.new/software-mansion/TypeGPU/eslint-plugin-typegpu@4408c8951852ba8e5341ed33bf0d8147bc59e404
https://pkg.pr.new/software-mansion/TypeGPU/tinyest@4408c8951852ba8e5341ed33bf0d8147bc59e404
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@4408c8951852ba8e5341ed33bf0d8147bc59e404
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@4408c8951852ba8e5341ed33bf0d8147bc59e404
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@4408c8951852ba8e5341ed33bf0d8147bc59e404
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@4408c8951852ba8e5341ed33bf0d8147bc59e404
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@4408c8951852ba8e5341ed33bf0d8147bc59e404
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@4408c8951852ba8e5341ed33bf0d8147bc59e404

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Sep 14, 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 [0.83, 1.77, 4.06, 6.14, 6.55, 10.63, 20.54, 20.29]
  line [0.91, 1.78, 3.75, 5.39, 6.61, 10.57, 21.23, 21.79]
  line [0.85, 1.70, 3.56, 5.67, 6.60, 10.37, 20.47, 21.04]
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.26, 0.46, 0.61, 0.74, 0.99, 1.11, 1.26, 1.40]
  line [0.29, 0.46, 0.61, 0.72, 1.01, 1.05, 1.26, 1.38]
  line [0.30, 0.45, 0.58, 0.72, 0.98, 1.01, 1.30, 1.38]
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 [0.78, 1.87, 3.28, 5.93, 10.52, 23.49, 49.09, 100.02]
  line [0.81, 1.99, 3.36, 5.97, 10.70, 22.88, 49.03, 96.98]
  line [0.87, 1.97, 3.25, 6.17, 11.05, 22.69, 46.93, 96.30]
Loading

@github-actions

Copy link
Copy Markdown

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

🟢 Decreased ➖ Unchanged 🔴 Increased ❔ Unknown
0 325 0 0

No notable changes.

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

@iwoplaza
iwoplaza force-pushed the fix/react-return-value-if-fulfilled branch from 87cdbd8 to 749ab17 Compare September 14, 2026 13:06
@iwoplaza
iwoplaza marked this pull request as ready for review September 14, 2026 13:06
Copilot AI lite review requested due to automatic review settings September 14, 2026 13:06

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.

🟡 Changes recommended

Two critical issues remain in root-context.tsx involving shared suspension state and incompatible Promise.resolve type inference.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates @typegpu/react root hooks to avoid unnecessary suspension after root fulfillment and adds lifecycle coverage.

Changes:

  • Adjusts root promise and suspension handling.
  • Adds tests for fulfillment, suspension, rejection, and hook ordering.
File summaries
File Description
packages/typegpu-react/tests/use-root.test.tsx Adds coverage for root hook behavior.
packages/typegpu-react/src/core/root-context.tsx Updates root promise handling and suspension behavior.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

| RootContextRejectedResult;

interface RootContext {
wasSuspended: boolean;
status: 'fulfilled',
value: root,
promise: Promise.resolve(root),
settledPromise: Promise.resolve({ status: 'fulfilled', value: root }),

@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 critical issues — one stale-comment nit inline.

Reviewed changes

  • Fulfilled-root discrimination — adds wasSuspended to RootContext, OwnRootContext and ExistingRootContext, and makes promise / settledPromise required on RootContextFulfilledResult.
  • useRoot / useRootOrError — early-return the fulfilled value when the context was never suspended on, otherwise use(...) the promise and reset the flag on success.
  • Tests — new use-root.test.tsx (11 cases): existing-root no-suspend, owned-root suspend→return, late mount after settle, hook-order stability, no-suspend when initialized by useRootWithStatus, and the error/rejection paths.

I verified the change locally: the new suite passes (11/11, 40/40 across the package), test:types is clean, and reverting the two hook bodies to the old promise ? use(...) : value logic makes the new tests fail — so the tests genuinely exercise the fix. The flag logic is safe: the early return only skips use for an already-fulfilled result, and a stale wasSuspended = true can at worst force a redundant use on a fulfilled promise, never a wrong value or a skipped required suspension.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/typegpu-react/src/core/root-context.tsx Outdated
@iwoplaza
iwoplaza force-pushed the fix/react-return-value-if-fulfilled branch from 749ab17 to 7dd37f9 Compare September 15, 2026 13:22

@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 in this delta — the per-hook useRef refactor is a clean narrowing of scope. Approval is withheld only because the earlier stale-comment thread above remains open, not because of any new finding.

Reviewed changes

  • Relocated suspension state — removed wasSuspended from the RootContext interface, OwnRootContext, and ExistingRootContext, replacing the shared field with a useRef(false) local to each of useRoot and useRootOrError. No other code referenced the field.
  • Kept the fulfilled-result contractRootContextFulfilledResult.promise / .settledPromise stay required, and ExistingRootContext still populates both with resolved promises; the early-return condition now reads !wasSuspended.current.

Placing the flag on a per-call ref is strictly better than the previous shared field: a suspension by one consumer can no longer force another consumer, or a caller on the module-level globalRootContextValue, onto the use(...) path. It remains safe because the early return only fires for status === 'fulfilled'. I verified the package suite (40/40 across 6 files) and pnpm --filter @typegpu/react test:types are green at c58fc5c6.

Pullfrog  | Fix it ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@iwoplaza
iwoplaza force-pushed the fix/react-return-value-if-fulfilled branch from c58fc5c to b7cd082 Compare September 16, 2026 08:08
@iwoplaza
iwoplaza force-pushed the fix/react-return-value-if-fulfilled branch from b7cd082 to 4408c89 Compare September 16, 2026 10:37

@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.

Reviewed changes

  • Reworded the suspension comment in useRoot and useRootOrError to describe the wasSuspended discriminator instead of the old "no promise to suspend on before" rationale. This addresses prior review feedback; the two hook bodies are otherwise unchanged.
  • Test-only cleanups (carried in the force-push): Catcher renders Error.message for Error instances, plus two Biome whitespace fixes.

The comment now matches the condition and the earlier open thread is resolved. I verified the package suite (40/40 across 6 files) and pnpm --filter @typegpu/react test:types are green at 4408c895.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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.

2 participants