
- Authors

- Name
- Nadim Tuhin
- @nadimtuhin
On this page
A browser automation script kept freezing text inputs on a React app built with Material UI. The script set the value and dispatched change and blur:
input.value = 'hello'
input.dispatchEvent(new Event('change', { bubbles: true }))
input.dispatchEvent(new Event('blur', { bubbles: true }))
On plain HTML pages, that works fine. On React, the input froze. The text showed up for one frame, then vanished on submit, or the input stopped responding to keystrokes.
Two things broke
The value tracker. React replaces the input's value property with its own tracker. Assigning input.value directly goes through that tracker, which records the new value as already seen. When React processes the change event, it checks whether the value differs from what it tracked. It doesn't, so React skips onChange, and the next render puts the old state back.
The blur. MUI inputs listen to blur to commit validation and shrink floating labels. When the script fired blur right after change, the blur handler ran before React processed the state update. The component locked focus and threw away the uncommitted input.
The fix
Call the native setter and dispatch only input:
const prototype = window.HTMLInputElement.prototype
const nativeSet = Object.getOwnPropertyDescriptor(prototype, 'value').set
nativeSet.call(input, 'hello')
input.dispatchEvent(new Event('input', { bubbles: true }))
The native setter skips React's tracker, so React sees a real change. It listens for the bubbling input event at the app's root, updates its tracker, and fires its own synthetic onChange. If you need direct component access, you can also read the Fiber key memoizedProps.onChange from the DOM node.
The takeaway: when you automate React forms, don't dispatch synthetic change or blur events. Use the native prototype setter and dispatch a single bubbling input event.
Related posts
- Claiming free game rewards with a Hermes cron job and Playwright
A cron job runs a small Playwright script every 6 hours to claim the free offers in a game web store. 50 saved runs show what it claims and how it fails.
- TIL: a gitignored sitemap goes stale (93 vs 123 URLs)
My IndexNow script read public/sitemap.xml and sent 93 URLs. The live sitemap had 123. The local copy is gitignored, so it only updates when I build.
- TIL: 'No module named' after an update meant a stale process
My agent said httpx was missing. It was installed. The running process had started before the update and was still on the old environment.