Engineering · · 8 min read
Why form fillers break on React (and Vue, and Angular) forms
If you've ever built a browser extension or bookmarklet to auto-fill test data, you've probably hit this: it works perfectly on a plain HTML form, and does absolutely nothing on a form built with React. The input looks like it updated for a split second, then snaps back to empty. No error, no console warning — it just doesn't stick.
This isn't a bug in your extension's logic. It's a fundamental mismatch between how the DOM works and how React, Vue, and Angular each think about form state — and the fix is different enough per framework that "just dispatch an event" only gets you halfway there.
- Setting
input.valuedirectly changes the DOM but not React's internal state, so the next re-render silently reverts it. - Dispatching a plain
inputevent after that doesn't help — React's own value tracker deduplicates it away. - The fix: call the native, un-patched value setter from the DOM prototype, then dispatch
input/change. - Vue's reactivity system and Angular's zone.js/NgModel hit similar walls, but for different underlying reasons — covered below.
- Checkboxes/radios don't need the native-setter trick at all: just call
.click().
- The naive approach, and why it fails
- Why dispatching a normal "input" event doesn't help either
- The fix: call the native setter directly
- Vue's reactivity: a related but different problem
- Angular: NgModel, zone.js, and why click() isn't always enough
- What about checkboxes and radios?
- One more gotcha: validation libraries that only run on blur
- Verify it yourself in 30 seconds
- Why this matters for QA
The naive approach, and why it fails
The obvious way to fill a text input is:
input.value = 'Jane Doe';
This works fine on a plain HTML input. But in a "controlled component" — the standard React pattern — the input's displayed value isn't really owned by the DOM at all. It's owned by React's state, and re-rendered on every keystroke via an onChange handler. When you set .value directly, you're changing the DOM node, but React has no idea it happened. On the very next re-render (which React schedules constantly), it overwrites your change with whatever is still in its own state — which is still empty.
Why dispatching a normal "input" event doesn't help either
The next thing people try is setting the value and then firing an event:
input.value = 'Jane Doe';
input.dispatchEvent(new Event('input', { bubbles: true }));
This still usually fails, for a subtler reason. React attaches its own internal value tracker to the native value property's setter. When you assign input.value = 'Jane Doe' directly, React's tracker records that the value "changed" to Jane Doe internally — but from React's perspective, since it thinks the DOM already matched its state before your assignment, the subsequent synthetic event gets deduplicated and dropped.
The fix: call the native setter directly
The reliable technique is to bypass the instance's own (React-patched) value setter and call the original one from the prototype directly:
function setNativeValue(el, value) {
const proto = el instanceof HTMLTextAreaElement
? window.HTMLTextAreaElement.prototype
: window.HTMLInputElement.prototype;
const setter = Object.getOwnPropertyDescriptor(proto, 'value').set;
setter.call(el, value);
el.dispatchEvent(new Event('input', { bubbles: true }));
el.dispatchEvent(new Event('change', { bubbles: true }));
}
Here's why this works: Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value') gets the original, un-patched property descriptor from the actual DOM prototype — not whatever React (or any other library) may have overridden on the instance. Calling that setter directly changes the underlying value without going through React's own tracking logic, so React's internal "did this change?" check on the next event correctly reports true, and the synthetic input event you dispatch afterward is treated as genuine user input. React re-renders with the new value in its state, and it sticks.
This same native-setter pattern also works for plain HTML and for any other library that wraps inputs the same way React does — it's not React-specific magic, it's just "talk to the real DOM setter instead of whatever the framework put in front of it."
Vue's reactivity: a related but different problem
Vue doesn't use controlled components in quite the same sense as React, but a Vue form bound with v-model has an analogous issue: v-model compiles down to a :value binding plus an @input listener that writes into a reactive ref. Vue's reactivity system (Proxies in Vue 3, getter/setter pairs in Vue 2) tracks changes made through its own reactive object — not changes made by mutating the rendered DOM node directly. Setting input.value from outside Vue's reactivity graph updates what's on screen for an instant, but the next reactive flush re-renders from the ref's actual value, which never changed, and your edit disappears exactly like the React case.
The practical fix is the same native-setter-plus-event approach: Vue's @input handler is a real DOM event listener under the hood, so a native input event dispatched after setting the value via the prototype setter reaches it correctly, updates the bound ref, and the value sticks through the next render. The one Vue-specific wrinkle: components using v-model.lazy listen for change instead of input, so if a field still reverts, dispatching change as well (as the snippet above already does) covers that case too.
Angular: NgModel, zone.js, and why click() isn't always enough
Angular's reactive forms and template-driven (NgModel) forms both ultimately rely on Angular's change detection to notice that something happened, and change detection is triggered by zone.js patching async browser APIs — including event listeners. A native input event dispatched via dispatchEvent does run inside zone.js's patched event-handling path in most cases, which is why the same native-setter technique generally works for Angular too. Where it gets trickier is with Angular Material form controls: components like mat-select or mat-datepicker aren't plain <input> elements at all under the hood — they're composed of multiple DOM nodes with Angular CDK overlay panels, and there's no single native setter to call. For those, the more reliable approach is simulating the actual interaction sequence a user would perform (click to open the overlay, then click the specific option), the same strategy this extension uses for select-like widgets it can't address directly.
What about checkboxes and radios?
Checkboxes and radio buttons have a different problem: setting .checked = true directly has the same "doesn't trigger the framework's change handler" issue, but there's no equivalent native-setter trick needed — the simplest fix is to just call element.click() instead of touching the property at all. A real click is indistinguishable from a user click as far as React, Vue, or Angular is concerned, checked state and change events included.
One more gotcha: validation libraries that only run on blur
Many form libraries (Formik, React Hook Form, Vuelidate, Angular's own updateOn: 'blur' option) only validate a field when it loses focus, not on every keystroke. If you fill a field and move straight to the next one without ever technically "blurring" the previous field via a native focus change, some validation state can be left stale. Dispatching a blur event on the last field you touch (after the whole form is filled) closes this gap reliably.
Verify it yourself in 30 seconds
You don't need to take any of this on faith — open devtools on any React form (even this site's own mock login forms work) and try both approaches back to back:
const el = document.querySelector('input[type=text]');
el.value = 'this will revert'; // watch it disappear on the next render
const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
setter.call(el, 'this will stick');
el.dispatchEvent(new Event('input', { bubbles: true }));
The first assignment visibly reverts (sometimes instantly, sometimes on your next keystroke or click elsewhere, depending on when React's next render happens to fire); the second one sticks and shows up correctly if you inspect the component in React DevTools.
One thing that won't reliably work: pasting via document.execCommand('insertText', ...). It's deprecated, inconsistently supported across browsers, and several frameworks' synthetic event systems don't recognize it as a real input source at all.
Why this matters for QA
If you're testing forms across a codebase that mixes plain HTML pages with React/Vue/Angular-driven ones — which describes most real production apps — a form filler that only handles the plain-DOM case will silently fail on exactly the pages that are usually the most complex to test by hand: multi-step checkouts, dynamic validation, conditional fields. The native-setter approach above is what makes the difference between "works on the login page" and "works everywhere."
FAQ
input.value directly changes the DOM node but not React's state, so the very next re-render overwrites your change with whatever React still has stored — usually empty.value setter, so a plain assignment followed by a dispatched event gets deduplicated and dropped. You need to call the original, un-patched setter from the DOM prototype first — see the code example above.v-model bindings and Angular's NgModel/reactive forms, since both ultimately listen for real DOM events. Angular Material components like mat-select are the exception — they have no single native setter, so they need simulated clicks instead.Further reading
- Auto Fill Fake Data vs Fake Filler: an honest comparison — including how the two handle framework-based forms differently.
- A practical checklist for testing multilingual forms — the other class of bugs that only shows up with real-world input.
Auto Fill Fake Data uses exactly this technique under the hood, plus locale-aware data generation — so forms fill correctly whether they're plain HTML or a fully controlled React form, in the page's own language.
See how it works