No ampdoc found error for nested forms in amp-list
What's the issue?
Forms using action-xhr are causing an Uncaught (in promise) Error: No ampdoc found for [object HTMLFormElement] error in the console. If the endpoint returns a 200 status then the submit-success binded to the form is correctly ran, however if the endpoint returns a 400 status the submit-error binded to the form does not run at all. This causes multiple areas of our websites to fail if the user hits any endpoints that return 400 status.

This only occurs for forms that are nested within an amp-list. I spoke to @sebastianbenz who suggested it may be an amp runtime issue, and he also suggested testing with the form outside of the amp-list to see if the error occurs still. Moving the form outside of the amp-list does fix this issue and prevent the error, however it's not a fix for us as we have many complex cases where we rely on the amp-list for several form attributes and data.
How do we reproduce the issue?
We've been unable to setup a reduced test case for this on any code playground, as it relies on us being able to set the endpoint response status. However we can provide a live example based on our client's site using the steps below. This isn't limited to our discount forms but it's the easiest to document and replicate.
- Add the following product to the basket: https://www.gaborshoes.co.uk/accessories-c32/handbags-c33/dina-ladies-messenger-handbag-p37007
- Go to the basket page: https://www.gaborshoes.co.uk/basket
- Click “Got a voucher code or gift card?”
4a. Enter the discount code
VSINVALIDand click apply to trigger the endpoint's 400 status. 4b. Enter the discount codeVSTESTand click apply to trigger the endpoint's 200 status.
Between 4a and 4B you may need to remove any applied discounts (ux above the discount box) and refresh the page.
Using the invalid discount code will trigger a 400 status, which currently shows the ampdoc error in the console and fails to run the submit-error code.
Using a valid discount will trigger a 200 status, which still shows the ampdoc error in the console but does successfully run the submit-success code.
Weirdly, if you first use the valid discount to trigger a success, then without refreshing the page remove that discount code and try VSINVALID to return a 400 status... you'll still get the error but the submit-error will correctly run.
Here's some massively reduced code derived from what we're currently using. The basket_endpoint is grabbed from our templating system, and basket is the initial state.
<amp-list
id="checkoutList"
binding="always"
src="<%= basket_endpoint %>"
[src]="basket ? basket : '<%= basket_endpoint %>'"
layout="fixed-height"
height="373"
items="."
single-item
>
<script type="text/plain" template="amp-mustache">
<form
id="checkoutOptions"
method="post"
action-xhr="<%= url_base %>/amp/basket"
on="submit: AMP.setState({
basket: {
info: {
errors: []
}
},
basket_loading: true
});
submit-success: AMP.setState({
basket_loading: null,
basket: event.response
});
submit-error: AMP.setState({
basket_loading: null,
basket: event.response
});"
>
{{ #info }}
<input
type="text"
id="basketDiscount"
name="discount_code"
>
<button type="submit">Apply</button>
{{ /info }}
</form>
</script>
</amp-list>
What browsers are affected?
All browsers, all devices.
Which AMP version is affected?
Version 2101230412006
This seems to be a recent issue that we've only spotted in the past couple of weeks. Previously this was fully working with no issues.