bikash-barnwal opened a new pull request, #43220:
URL: https://github.com/apache/superset/pull/43220

   ### SUMMARY
   
   `TextControl` derived a display value during render when its `value` prop 
changed, but never wrote it back to local state:
   
   ```ts
   let displayValue = localValue;
   if (safeStringify(prevValueRef.current) !== safeStringify(value)) {
     prevValueRef.current = value;      // marker updated…
     displayValue = safeStringify(value); // …but localValue left stale
   }
   ```
   
   Updating the ref means the branch does not run again. So the render that 
changed the value shows the new text, and the **next** render — one triggered 
by any unrelated prop, which no longer enters the branch — falls back to 
`localValue` and puts the superseded text back in the input.
   
   The user-visible effect is a programmatic value change that appears to apply 
and then silently reverts: an undo, a control-panel reset, or form data 
replaced when switching chart type.
   
   The fix adjusts state during render, which is React's documented pattern for 
deriving state from props: set both the previous-value marker and the local 
value, then render from local state. React re-runs the component immediately 
and never commits the intermediate output.
   
   Found by scanning for stale-derived-state shapes rather than from a filed 
issue.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   Before: set Row limit programmatically to 200 → the field shows 200, then 
flips back to 100 on the next re-render.
   After: it stays 200.
   
   ### TESTING INSTRUCTIONS
   
   ```bash
   cd superset-frontend
   npm run test -- src/explore/components/controls
   ```
   
   New test re-renders three times — initial value, externally changed value, 
then an unrelated prop change — and asserts the input still shows the new 
value. It fails on master at the third step (`Unable to find an element with 
the display value: 200`).
   
   **601 of 602 tests pass across all 73 control suites** (1 pre-existing 
skip), so no consumer of this widely-used control regressed.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [x] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to