-
Notifications
You must be signed in to change notification settings - Fork 50.6k
Description
Bug Description
In fixtures/attribute-behavior/src/App.js, the componentWillUnmount method has a bug where it checks for this.timeout but clears this.interval (which doesn't exist). This causes a memory leak where timeouts are never properly cleaned up on component unmount.
Location: fixtures/attribute-behavior/src/App.js:605
Code Analysis
Current (Buggy) Code:
componentWillUnmount() {
if (this.timeout) {
clearTimeout(this.interval); // ❌ Error: this.interval is undefined
}
}
Proposed Fix:
componentWillUnmount() {
if (this.timeout) {
clearTimeout(this.timeout); // ✅ Correct: matches the variable being tracked
}
}
Steps To Reproduce
- Navigate to the fixtures/attribute-behavior directory.
- Run the build and dev server:
yarn build --type=UMD_DEV react/index,react-dom && cd fixtures/attribute-behavior && yarn install && yarn dev - Open the fixture in a browser.
- Hover over a result cell to trigger onMouseEnter (which sets this.timeout).
- Unmount the component before the timeout fires (e.g., navigate away or close the tab).
- Observe: The timeout is never cleared, which can lead to memory leaks or setState warnings on unmounted components.
Current Behavior
When the component unmounts, the code checks for this.timeout but calls clearTimeout(this.interval). Since this.interval is undefined, the actual timer remains active, potentially causing "cannot update state on an unmounted component" warnings.
Expected Behavior
The componentWillUnmount lifecycle should correctly call clearTimeout(this.timeout) to ensure the specific timer initiated by the component is destroyed immediately upon unmounting.
Suggested Fix (Diff)
--- fixtures/attribute-behavior/src/App.js
+++ fixtures/attribute-behavior/src/App.js
@@ -603,5 +603,5 @@
componentWillUnmount() {
if (this.timeout) {
-
clearTimeout(this.interval);
-
}
clearTimeout(this.timeout);
}