Repository: facebook/react
File: packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js (JavaScript)

Code before:
  if (formData != null) {
    // $FlowFixMe[prop-missing]: FormData has forEach.
    formData.forEach(pushAdditionalFormField, target);
  }
}

function getCustomFormFields(
  resumableState: ResumableState,
  formAction: any,
): null | ReactCustomFormAction {
  const customAction = formAction.$$FORM_ACTION;
  if (typeof customAction === 'function') {
    const prefix = makeFormFieldPrefix(resumableState);
    try {
      return formAction.$$FORM_ACTION(prefix);
    } catch (x) {
      if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
        // Rethrow suspense.
        throw x;
      }
      // If we fail to encode the form action for progressive enhancement for some reason,
      // fallback to trying replaying on the client instead of failing the page. It might
      // work there.
      if (__DEV__) {
        // TODO: Should this be some kind of recoverable error?
        console['error']('Failed to serialize an action for progressive enhancement:\n%o', x);
      }
    }
  }
  return null;
}

function pushFormActionAttribute(
  target: Array<Chunk | PrecomputedChunk>,
  resumableState: ResumableState,
  renderState: RenderState,
  formAction: any,
  formEncType: any,
  formMethod: any,
  formTarget: any,
  name: any,
): void | null | FormData {
  let formData = null;
  if (enableFormActions && typeof formAction === 'function') {
    // Function form actions cannot control the form properties
    if (__DEV__) {
      if (name !== null && !didWarnFormActionName) {
        didWarnFormActionName = true;
        console.error(
          'Cannot specify a "name" prop for a button that specifies a function as a formAction. ' +
            'React needs it to encode which action should be invoked. It will get overridden.',

Review comment (bug):
There's something weird happening if I don't do the `console['error']` hack to avoid our rewrite.

In the current state it doesn't fail tests for some reason even with the logs which seems broken.

If I change it, it fails tests but then asserting on the tests passing doesn't work due to the extra arguments. So something is very messed up with how we do assertions on these.

Edit: Found a string that it seems satisfied with but not sure why.

Code after:
  if (formData != null) {
    // $FlowFixMe[prop-missing]: FormData has forEach.
    formData.forEach(pushAdditionalFormField, target);
  }
}

function getCustomFormFields(
  resumableState: ResumableState,
  formAction: any,
): null | ReactCustomFormAction {
  const customAction = formAction.$$FORM_ACTION;
  if (typeof customAction === 'function') {
    const prefix = makeFormFieldPrefix(resumableState);
    try {
      return formAction.$$FORM_ACTION(prefix);
    } catch (x) {
      if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
        // Rethrow suspense.
        throw x;
      }
      // If we fail to encode the form action for progressive enhancement for some reason,
      // fallback to trying replaying on the client instead of failing the page. It might
      // work there.
      if (__DEV__) {
        // TODO: Should this be some kind of recoverable error?
        console.error(
          'Failed to serialize an action for progressive enhancement:\n%s',
          x,
        );
      }
    }
  }
  return null;
}

function pushFormActionAttribute(
  target: Array<Chunk | PrecomputedChunk>,
  resumableState: ResumableState,
  renderState: RenderState,
  formAction: any,
  formEncType: any,
  formMethod: any,
  formTarget: any,
  name: any,
): void | null | FormData {
  let formData = null;
  if (enableFormActions && typeof formAction === 'function') {
    // Function form actions cannot control the form properties
    if (__DEV__) {
      if (name !== null && !didWarnFormActionName) {
        didWarnFormActionName = true;