amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Form submit service failed: %s: Cannot read property 'fire' of undefined

Open ThongSaltire opened this issue 7 years ago • 1 comments

What's the issue?

This issue is not happened with the previous version of amp. Amp-form couldn't be submitted because it cannot read property 'fire' of undefined. Further investigated, we noticed an error in amp-form.js amp-form.js:365 Uncaught (in promise) TypeError: this.Ba.whenNextVisible is not a function. The issue was resolved when we rolled back to the previous version of amp, in particular the amp version 1909181902540 doesn't have this issue.

How do we reproduce the issue?

  • Open this link: https://www.greatmats.com/mats/foam-floor-mats.php
  • Click on quick calculator
  • Enter width and length and submit
  • The form cannot be submitted

What browsers are affected?

All browsers

Which AMP version is affected?

This is a new issue. We rolled back to the previous 1909181902540 and the form was submitted normally

ThongSaltire avatar Oct 09 '19 19:10 ThongSaltire

It looks like there is a property naming conflict due to compilation. The following lines of code for retrieving an AmpDoc check for a cached value here:

https://github.com/ampproject/amphtml/blob/c6830847f91b526bf714a8adfae6efc52a69b5ed/src/service/ampdoc-impl.js#L172-L174

The code is compiled to the following in version 1910071804120:

if (a.w)
  return a.w;

However, since the element we are looking up on is a <form> element, it apparently gains properties based on the name attribute of child form elements (<input>s, <button>s?, etc?). In this form, happens to be a form element <input name="w" ...> This means that the form.w is the input element. The ampdoc lookup code then thinks that this is a cached ampdoc reference and returns it as if it were one.

I'm not sure, but I think it is generally safe to set expando properties on DOM elements in Closure Compiler and not have those conflict with built-in fields that are declared in externs. In this case, I think there is a problem.

The property is non-enumerable, but we can't check that (using propertyIsEnumerable) due to renaming in the compiler. We could do something like:

const ampDoc = n.ampDoc_;
if (ampDoc) {
  n.ampDoc_= null;
  if (n.ampDoc_ === null) {
    n.ampDoc_ = ampDoc;
    return ampDoc;
  }
}

since you cannot actually overwrite the property created by the child form name (has no setter?). Perhaps we can just ignore form elements explicitly here (or explicitly check for AMP elements with n.nodeName.startsWith('AMP-')).

There may be other parts of the code base that run into similar issues, though I'm not sure if we would be able to find those up front.

sparhami avatar Oct 09 '19 21:10 sparhami