fix(docs): Clear timeout in 3D Fish example#2311
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (344 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
There was a problem hiding this comment.
Pull request overview
Updates the TypeGPU docs “3D Fish” rendering example to avoid applying delayed preset updates after the example has been cleaned up/unmounted.
Changes:
- Introduces a
disposedflag for lifecycle tracking. - Guards the delayed preset-reset timeout callback to no-op after cleanup.
- Marks the example as disposed during
onCleanup().
Comments suppressed due to low confidence (1)
apps/typegpu-docs/src/examples/rendering/3d-fish/index.ts:86
enqueuePresetChanges()schedules a timeout but doesn't keep the timer id, soonCleanup()cannot actually clear it. Thedisposedguard avoids writes after cleanup, but the pending timer still fires and can also stack ifenqueuePresetChanges()is called repeatedly within 300ms (potentially resettingspeedMultiplierearly). Store thesetTimeoutreturn value, clear any previous pending timeout before scheduling a new one, and clear it inonCleanup()to match the PR intent and avoid lingering callbacks.
window.setTimeout(() => {
if (disposed) return;
fishBehaviorBuffer.write(presets.default);
spinnerBackground.style.display = 'none';
speedMultiplier = 1;
}, 300);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
When can this dispose matter? Is it when the fish haven't finished loading yet? |
@aleksanderkatan Yes, it's when somebody would change a preset (or open up the example), then leave before it finished loading. |
No description provided.