Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions examples/onReset/app-buggy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useEffect, useRef } from 'react';

function App() {
const ref = useRef<HTMLFormElement | null>(null);

// Handle form submission safely with DOM types
const handleSubmit = (e: SubmitEvent) => {
e.preventDefault();
if (e.currentTarget instanceof HTMLFormElement) {
console.log('submit action');
e.currentTarget.reset();
}
};

useEffect(() => {
const form = ref.current;

const onReset = (e: Event) => {
console.log('native reset', e);
};

if (form) {
form.addEventListener('reset', onReset);
form.addEventListener('submit', handleSubmit);

return () => {
form.removeEventListener('reset', onReset);
form.removeEventListener('submit', handleSubmit);
};
}
}, []);

return (
<div>
<p>
When pressing the reset button or submitting the form, both the custom
handler and native reset event fire consistently.
</p>
<form ref={ref}>
<input name="name" type="text" />
<input type="submit" />
<input type="reset" />
</form>
</div>
);
}

export default App;
49 changes: 49 additions & 0 deletions examples/onReset/app-fixed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useEffect, useRef } from 'react';

function App() {
const ref = useRef<HTMLFormElement | null>(null);

// Handle form submission using native DOM type
const handleSubmit = (e: SubmitEvent) => {
e.preventDefault();
if (e.currentTarget instanceof HTMLFormElement) {
console.log('submit action');
// Manually reset the form
e.currentTarget.reset();
}
};

useEffect(() => {
const form = ref.current;

const onReset = (e: Event) => {
console.log('native reset', e);
};

if (form) {
form.addEventListener('reset', onReset);
form.addEventListener('submit', handleSubmit);

return () => {
form.removeEventListener('reset', onReset);
form.removeEventListener('submit', handleSubmit);
};
}
}, []);

return (
<div>
<p>
When pressing the reset button or submitting the form, both the React onReset prop and native
reset event are fired consistently.
</p>
<form ref={ref} onReset={(e) => console.log('onReset prop', e)}>
<input name="name" type="text" />
<input type="submit" />
<input type="reset" />
</form>
</div>
);
}

export default App;
16 changes: 1 addition & 15 deletions packages/shared/ReactVersion.js
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// TODO: this is special because it gets imported during build.
//
// It exists as a placeholder so that DevTools can support work tag changes between releases.
// When we next publish a release, update the matching TODO in backend/renderer.js
// TODO: This module is used both by the release scripts and to expose a version
// at runtime. We should instead inject the version number as part of the build
// process, and use the ReactVersions.js module as the single source of truth.
export default '19.1.0';
export default '19.2.0-canary-edac0dde-20250723';