Follow up on https://github.com/Automattic/amp-wp/pull/1048#issuecomment-379167176
I want to follow up later with some more improvements including the added ability to knowingly bypass removal of elements, attributes, and styles that are invalid but which a given site cannot afford to be removed. I'm thinking we'd want CSS over the 50KB limit to default to not be removed, even if that means it is invalid AMP. In terms of implementation here, I think this can be implemented by allowing the validation_error_callback to return false as a way to prevent removal from happening. That would allow a theme/plugin to decide on a case-by-case basis which things should get removed. This is in regards to https://github.com/Automattic/amp-wp/pull/1048#pullrequestreview-108681682 and https://github.com/Automattic/amp-wp/pull/1048#discussion_r178599928
There are a few validation errors that should specifically be not sanitized by default since they could seriously impact a site:
- Keyframe properties that aren't hardware accelerated.
- CSS exceeding 50KB.
- External stylesheets that can't be inlined.
- …
In addition to allowing the user to manually acknowledge whether a given validation error should be considered critical or be ignored (#1003), there also needs to be a way to dynamically make this decision based on a user-supplied validation callback, a capability which would also be used in #1087 to check whether a validation error is a deal breaker for serving AMP for the current page.
Todo
- [ ] When a deal-breaker validation error occurs, prevent AMP from being served from a given URL.
- [ ] Make sure that error codes are distinct enough to be differentiated.
- [ ] Make sure that validation errors still display when editing a post.
- [x] Make sure that sources are located when not serving validation errors from cache (pass
$nodeto methods). - [ ] 🚫 ~Decide on which validation errors should not result in sanitization by default (if any).~
- [ ] 🚫 ~Consider having a AMP admin setting for whether to allow select validation errors when they occur.~
- [ ] 🚫 ~Look at factoring in sanitization-skipping to paired mode, to serve
canonicaldirty AMP documents but valid non-canonical (amphtml) ones. This is similar to incorporating prerendering into the postprocessing flow (#958).~
Closes #956
该提问来源于开源项目:ampproject/amp-wp