amp-bind: Expression complexity limit reached
What's the issue?
We need to perform over 50 expressions in unique AMP page, how can we do it?
How do we reproduce the issue?
Below a demo AMP product page with the errors. https://www.giglio.com/borse-donna_borsa-mano-borsa-petite-2-jours-piccola-con-barra-metallica-logo-inciso-fendi-8bh2533wl.html?cSel=027&AAMMPP
What browsers are affected?
All browsers
Which AMP version is affected?
V0
@Gigliocom - Thanks for reaching out! Could you provide detailed steps on how to reproduce the issue (and what this issue is).
I did not see any errors on the link above.
Hi, when you click on thumb to choose another color, the main photo must be change and the hidden values into form must change also. But that does not.
In console.log appear this: error.js:169 amp-bind: Expression eval failed with error: Expression size (52) exceeds max (50). Please reduce number of operands. Uncaught (in promise) Error: amp-bind: Expression eval failed with error: Expression size (52) exceeds max (50). Please reduce number of operands. reported
/to @choumx
Hi Giglio.com, thanks for your feedback. The expression complexity limit is intended to keep pages using amp-bind fast and responsive.
One way you can simplify your page expressions (and speed up the page itself!) is to reduce the number of variables. Specifically, I think you can remove the selectedSlideFor* variables.
Instead of showing/hiding 4 different <amp-carousel> elements based on the selected color, try using a single <amp-carousel> with its <amp-img> children changing their src via a [src] binding. For example:
<amp-state id="product">
{
"027": {
"image1": "images/027/1.jpg",
"image2": "images/027/2.jpg",
...
}
}
</amp-state>
<amp-carousel>
<amp-img [src]="product[selectedColor].image1"></amp-img>
<amp-img [src]="product[selectedColor].image2"></amp-img>
</amp-carousel>
Hope that helps!
Hi @choumx, thanks for your help, but i think that this is not solution. We have products that has many photo per colors but unfortunately any colors dont'have the same number of pictures.
There is an another way to execute more than 50 expressions?
We have products that has many photo per colors but unfortunately any colors dont'have the same number of pictures.
Ah, yes. We're planning to support more dynamic slide content in amp-carousel (#8921). One temporary workaround is to create a carousel with the max number of images among your products, and hide or replace overflow images with a stock image.
There is an another way to execute more than 50 expressions?
Not at the moment, though we may revisit this if it's a common problem -- I'll use this issue to track. Intermediary variables would also help reduce duplication of expression fragments in your case (#8397).
Sorry that you're have difficulties with amp-bind. We'll try to improve this soon.
This issue doesn't have a category which makes it harder for us to keep track of it. @choumx Please add an appropriate category.
Definitely need to increase the limit. I'm creating a page with personalised products. Customer have options to choose designs, colours, pictures, fonts and enter custom text. We are using amp-bind to build up a preview link. 50 operands are definitely not enough. Alternatively, is there any ways I can encode the state json object and pass to the server as an parameter?
@ivanliu8 Can you share a sample page with expressions that exceed this limit?
may i know how do you calculate the operands ? such as AstNodeType.NOT is equivalent to how many operands , AstNodeType.TERNARY is equivalent to how many operands, a reference to the source code would be much appreciated. Thx in advanced ! @choumx
"Operand" is loosely defined here. 😄 It's technically the number of nodes in the abstract syntax tree of the expression.
I'd really appreciate any example pages that exceed the operand limit. This way we can thoughtfully support your use cases without necessarily changing the performance characteristics of amp-bind.
a work around trick would be:
based on the documentation, input would support both tap and change actions. So, basically you can create a transparent dummy input in front of your <element>
a simple demo as below:
- set the parent
position: relative
code:
<input type="checkbox" class="dummy-checkbox" on="
tap: AMP.setState({
50 operands bla bla bla
});
change: AMP.setState({
50 operands bla bla bla
})">
css:
.dummy-checkbox {
opacity: 0;
position: absolute;
width: 100%;
height: 100%;
z-index: 1;
}
HI ,
I am facing the same issue, I try to pass say 10 or more state parameters in url, but it is failing amp-bind: Expression compile error in Expression size (61) exceeds max (50). Please reduce number of operands.
@gtonysam Which component URL are you mutating? amp-list or amp-state?
Something like #13079 may help you by allowing use of state variables in URL substitutions without a complex expression.
@choumx Hi we are using amp-state to bind the values to the url. We have as many as 20 paramters to pass to the url. We tried amp-bind macro as well to add values but still the below issue comes always- amp-bind :Expression compile error in Expression size () exceeds max (50). Please reduce number of operands.
Can you share the markup for this element?
Hi Choumx,
This is what I am trying to do,
<amp-bind-macro id="dynamicDate" arguments="" expression="searchForm.departureDay+searchForm.departureMonthURL+searchForm.departureMonth+searchForm.departureYearURL" />
<amp-bind-macro id="LocationURL" arguments="" expression="searchForm.originLocationURL+searchForm.source+searchForm.destinationLocationURL+searchForm.destination" />
<amp-bind-macro id="dynamicURL" arguments="" expression="searchForm.baseurl+searchForm.tripType+dynamicDate()+LocationURL()+searchForm.endURL" />
This is just a part of url and few more operands needs to be added and I am unable to add one more operand as it exceed the limit
Where is dynamicURL used in your case?
It looks like most of these variables are from <input> fields of a form. Have you considered flipping the logic? E.g. use amp-bind to modify the values of these inputs (e.g. [value] binding) and submit the form when ready?
dynamicURL is the base url, the searchform parameters are to be passed in the url. But the url is not a straightforward one as it contains string values.
Example of sample url : https://example.com/&outboundOption.departureDay=+"SearchForm.startDate"+/&outboundOption.departureMonth=+"SearchForm.startMonth"
The searchform values are dynamic values. We used amp-macro-bind , still the size limit exceeds. So we need to append multiple string values as well as input values.
[href]="searchForm.arevaluesChanged ? dynamicURL() : searchForm.defaulturl
@choumx Any updates please ?