-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSR: Transforming of nodes with attribute 'heights' fails, if value contains multiple media queries #1304
Comments
Thanks for the detailed write up! We should also fix the underlying issue of media condition parsing not being properly implemented. |
You're welcome! |
Not that I'm aware of. There is https://github.com/albell/parse-sizes as a lightweight standalone solution (haven't tested it). If the sizes attribute is valid, we shouldn't have a problem transforming the attribute as we can use the whole media query. We need to be able to tell though if the sizes attribute is valid. |
Just published 2.8.9. Thanks for the reminder :-) |
Issue
A node fails transforming, if it has 'heights'-attribute which contains more than one media query.
Also the attribute got removed on rendering, if it had failed on transforming.
For example
Will be rendered by amp framework, without any validation errors and with correct media queries. But on SSR with amp optimizer i get following error and the 'heights'-attribute will be removed on rendered amp page:
Reason
parseSizes(string)
throws an error for strings which has more than one ')' and trailing characters.amp-toolbox/packages/optimizer/lib/parseSizes.js
Lines 61 to 64 in b367a2d
When function
transform(node, id)
ofHeightsTransformer
gets called on nodes with 'height'-attributes, which contain a value with multiple media queries,parseSizes(string)
will throw an error andApplyCommonAttributes
will catch that error and logs them.amp-toolbox/packages/optimizer/lib/transformers/ApplyCommonAttributes.js
Lines 206 to 214 in b367a2d
In function
applyToCustomStyles(head, customStyles)
ofApplyCommonAttributes
the attributes 'heights', 'media' and 'sizes' will be removed on nodes which are in arraynodesToTransform
and my own value in 'heights'-attribute (which could not be transformed) will be removed. So the result is, the rendered amp component has no 'heights' attribute at all.amp-toolbox/packages/optimizer/lib/transformers/ApplyCommonAttributes.js
Lines 246 to 250 in b367a2d
Solutions
First possible solution
One possible solution would be, that nodes which could not be transformed should be removed from array
nodesToTransform
, so the values could stay if transformation fails.This could be done with following code:
In context it would look like that:
Second possible solution
An other solution would be, that function
parseSize(string)
would accept all values which amp framework does.Maybe for the second solution it would make sense, to ignore all nodes where parseSizes(string) could not parse values, too.
PR
I've created a PR with a fix described in first solution: #1305
The text was updated successfully, but these errors were encountered: