amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Stringent validation protocol for boilerplate causes a major nuisance for editor with auto-format

Open zipswich opened this issue 8 years ago • 6 comments

What's the issue?

I use Visual Studio (VS) for ASP.Net MVC web applications (each website is an MVC project). I started to AMPlify a website after attending the team's fantastic roadshow on Tuesday. Actually, AMP goes really well with MVC.

VS auto-formats the file after pasting code. The boilerplate will not pass validation after auto-formatted to the following:

  <style amp-boilerplate>
        body {
            -webkit-animation: -amp-start 8s steps(1,end) 0s 1 normal both;
            -moz-animation: -amp-start 8s steps(1,end) 0s 1 normal both;
            -ms-animation: -amp-start 8s steps(1,end) 0s 1 normal both;
            animation: -amp-start 8s steps(1,end) 0s 1 normal both
        }

        @-webkit-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @-moz-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @-ms-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @-o-keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }

        @keyframes -amp-start {
            from {
                visibility: hidden
            }

            to {
                visibility: visible
            }
        }
    </style>
    <noscript>
        <style amp-boilerplate>
            body {
                -webkit-animation: none;
                -moz-animation: none;
                -ms-animation: none;
                animation: none
            }
        </style>
    </noscript>

VS auto-formats the entire file after each pasting. VS has an issue in disabling auto-format, but many may not want to disable it because it is a useful feature. Now, I have to copy and paste the boilerplate, then undo the formatting periodically.

How do we reproduce the issue?

Use VS to AMPlify a cshtml file and paste some code.

What browsers are affected?

N/A

Which AMP version is affected?

The latest.

Is this a new issue? Or was it always broken? Paste your AMP version. You can find it in the browser dev tools. Not sure.

I'd like to suggest allowing formatted boilerplate.

zipswich avatar Aug 09 '18 14:08 zipswich

There are a variety of possible html-munging steps that various tools may choose to take when run on AMP html. This is one such example, but other tools may add comments, reorder @ rules, insert semicolons, etc. It is impossible to accommodate every possible mutation. The least ambiguous place to draw the line is strict string match to the provided boilerplate.

Adding extra relaxation logic introduces maintenance as one cannot restore the constraints later should a need arise. The method gets larger and slower, limiting the contexts in which it can be executed, such as running this in a browser. The performance impact is to every user of AMP validation, including those not munging the source.

The current rules support variable-length whitespace in the locations in the boilerplate where whitespace is mandatory (ex: '-amp-start 8s', but not where it is optional) and at the begin/end of the CSS block as a compromise. I'm reluctant to go further, but will leave this issue open for discussion.

Gregable avatar Aug 10 '18 17:08 Gregable

Thank you for the explanation. Is it possible to get some sense (just some sense, not accurate data) about which tools cover how much share of web developers. If three tools cover 80+% developers, maybe accommodating them will be sufficient. Another option is making a Visual Studio plug-in like this one specifically for AMP. I know this is supposed to be beyond the scope of the AMP team, but it would be so nice to have an official AMP plug-in from the team. This would be another, albeit small, enticement for the large number of .Net enterprise web developers.

zipswich avatar Aug 11 '18 01:08 zipswich

This fix should be included in the next week's release (by October, 19th).

dparikh avatar Oct 12 '18 23:10 dparikh

Fantastic!

zipswich avatar Oct 13 '18 02:10 zipswich

The issue is now fixed and in PROD. Please, test and provide feedback if any issues.

dparikh avatar Oct 17 '18 20:10 dparikh

Now, I am getting green validation stamp by AMP Validator 1.1.4 with Visual Studio auto-formatted amp-boilerplate.
Thanks a lot.

zipswich avatar Oct 19 '18 13:10 zipswich