listenToFormSubmissionsForReplaying() — react Function Reference
Architecture documentation for the listenToFormSubmissionsForReplaying() function in ReactDOMFizzInstructionSetShared.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 1df64080_6b91_5ac1_a5a0_0d8b39393a95["listenToFormSubmissionsForReplaying()"] 2a61726f_9a35_9713_662f_bfb1ef81f49f["ReactDOMFizzInstructionSetShared.js"] 1df64080_6b91_5ac1_a5a0_0d8b39393a95 -->|defined in| 2a61726f_9a35_9713_662f_bfb1ef81f49f style 1df64080_6b91_5ac1_a5a0_0d8b39393a95 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js lines 600–653
export function listenToFormSubmissionsForReplaying() {
// A global replay queue ensures actions are replayed in order.
// This event listener should be above the React one. That way when
// we preventDefault in React's handling we also prevent this event
// from queing it. Since React listens to the root and the top most
// container you can use is the document, the window is fine.
// eslint-disable-next-line no-restricted-globals
addEventListener('submit', event => {
if (event.defaultPrevented) {
// We let earlier events to prevent the action from submitting.
return;
}
const form = event.target;
const submitter = event['submitter'];
let action = form.action;
let formDataSubmitter = submitter;
if (submitter) {
const submitterAction = submitter.getAttribute('formAction');
if (submitterAction != null) {
// The submitter overrides the action.
action = submitterAction;
// If the submitter overrides the action, and it passes the test below,
// that means that it was a function action which conceptually has no name.
// Therefore, we exclude the submitter from the formdata.
formDataSubmitter = null;
}
}
if (action !== EXPECTED_FORM_ACTION_URL) {
// The form is a regular form action, we can bail.
return;
}
// Prevent native navigation.
// This will also prevent other React's on the same page from listening.
event.preventDefault();
// Take a snapshot of the FormData at the time of the event.
const formData = new FormData(form, formDataSubmitter);
// Queue for replaying later. This field could potentially be shared with multiple
// Reacts on the same page since each one will preventDefault for the next one.
// This means that this protocol is shared with any React version that shares the same
// javascript: URL placeholder value. So we might not be the first to declare it.
// We attach it to the form's root node, which is the shared environment context
// where we preserve sequencing and where we'll pick it up from during hydration.
// If there's no ownerDocument, then this is the document.
const root = form.ownerDocument || form;
(root['$$reactFormReplay'] = root['$$reactFormReplay'] || []).push(
form,
submitter,
formData,
);
});
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does listenToFormSubmissionsForReplaying() do?
listenToFormSubmissionsForReplaying() is a function in the react codebase, defined in packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js.
Where is listenToFormSubmissionsForReplaying() defined?
listenToFormSubmissionsForReplaying() is defined in packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js at line 600.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free