fix(city): clear pending InstancedBuildings safety timers during lifecycle changes (#291)#414
fix(city): clear pending InstancedBuildings safety timers during lifecycle changes (#291)#414itssagarK wants to merge 23 commits into
Conversation
|
@itssagarK is attempting to deploy a commit to the ixotic27-8245's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @Ixotic27, I've submitted a fix for #291. This PR introduces a persistent timer reference and ensures pending safety timers are cleared both before new timers are scheduled and during component cleanup. The goal is to prevent delayed callbacks from executing after lifecycle changes and avoid unnecessary work on stale references. Thank you for reviewing. |
|
Hi @itssagarK! 👋 I've reviewed your PR code for resolving issue #291. There is a React Hook rule violation in const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);You declared Since the Please fix this so we can merge your changes! Thank you! |
|
🚨 Hey @itssagarK, the CI Pipeline is failing on this PR and it has been marked as 🔍 What failed:
📋 Error Details (first 2):
Please fix the issues before this can be reviewed. Here's how: 1. Run checks locally before pushing: npm run lint # Run ESLint
npm run build # Verify production build passes2. Auto-fix common issues: npm run lint -- --fix # Auto-fix lint errors where possible3. Check the full failure log here: Once you push a fix and the CI passes, the |
I've updated the implementation and removed the Hook usage from inside the effect. The timer is now managed using a local `safetyTimer` variable within the effect scope and is cleared during cleanup whenever dependencies change or the component unmounts. This keeps the solution aligned with React's Rules of Hooks while preserving the intended timer cleanup behavior.
|
Hi @Ixotic27, Thank you for the review. I've updated the implementation and removed the Hook usage from inside the effect. The timer is now managed using a local This keeps the solution aligned with React's Rules of Hooks while preserving the intended timer cleanup behavior. Thank you for the feedback. Please take another look when you have time. |
What does this PR do?
This PR fixes a lifecycle issue in
InstancedBuildingswhere delayed initialization timers could continue running after component updates or unmounts.Previously, the component relied on a timeout-based safety mechanism, but rapid layout changes or component lifecycle transitions could leave pending callbacks scheduled against stale component state and references.
This PR ensures that pending timers are consistently cleaned up before new timers are created and when the component unmounts.
Changes Made
src/components/InstancedBuildings.tsx
timerRefusinguseRef.timerRef.Why this matters
Without this fix:
With this fix:
Related Issue
Fixes #291
Checklist
npm run lintpasses