Skip to content
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

Map Block AMP Compatibility Alternate Approach #13405

Merged
merged 18 commits into from
Nov 22, 2019

Conversation

jeffersonrabb
Copy link
Contributor

@jeffersonrabb jeffersonrabb commented Sep 3, 2019

Changes proposed in this Pull Request:

This PR is an alternate approach to #13321, which came about due to problems described in #13321 (comment). In this approach, a URL param (map-block-counter) will cause page requests to render a complete document containing only a single Map block. The value of map-block-counter determines the ordinal of the block to render. If no block at the provided value is found, the page renders normally. In AMP requests, Map block will render as an iFrame using the special URL as the src. This approach replaces the srcdoc attribute and length/browser compatibility constraints associated with it. DOMDocument is used to extract the desired block markup from the post content.

TODO:

  • Improve map height inside of iframe.
  • Determine if width/height of amp-iframe are correct, and whether intrinsic or responsive layout should be used.
  • How to sanitize the full page output?
  • If problematic, there may be viable alternatives to ordinal, for example a hash of the Map block markup.

Is this a new feature or does it add/remove features to an existing part of Jetpack?

  • Adds AMP compatibility to Map block.

Testing instructions:

  • Activate AMP plugin.
  • Add Map block to content.
  • View post/page in AMP.
  • Verify Map block still renders on a valid AMP page.
  • Verify Map block renders in the loop, e.g. on homepage.
  • Verify pages with multiple Map blocks render correctly.
  • Inspect page and copy the src of the amp-iframes. Load these URLs in separate browser windows. Make sure they render correctly.
  • Alter the value of map-block-post-id and/or map-block-counter query params. This should cause the full page to load rather than the block alone.

Proposed changelog entry for your changes:

  • Add AMP-compatibility to the Map block.

@jeffersonrabb jeffersonrabb requested a review from a team September 3, 2019 16:34
@jeffersonrabb jeffersonrabb added DO NOT MERGE don't merge it! [Status] In Progress AMP [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Block] Map labels Sep 3, 2019
@jetpackbot
Copy link
Collaborator

jetpackbot commented Sep 3, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: December 3, 2019.
Scheduled code freeze: November 26, 2019

Generated by 🚫 dangerJS against d9492d1

Copy link
Contributor

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clever approach! It should work well when the map blocks are inside of post_content. Checks need to be added for when this is not the case, however (e.g. on archive templates that use the_content()). Also, I suppose the block will just have to show nothing when it is being rendered outside of post content, e.g. sidebar, header, footer?

@jeffersonrabb jeffersonrabb force-pushed the add/amp-block-amp-without-srcdoc branch from e651d6f to 89cd41a Compare September 29, 2019 20:50
@jeffersonrabb
Copy link
Contributor Author

@westonruter the iframe sizing should be resolved in 3a0a117

@jeffersonrabb jeffersonrabb added [Status] Needs Review This PR is ready for review. and removed DO NOT MERGE don't merge it! [Status] In Progress labels Oct 1, 2019
@jeherve jeherve added this to the 8.0 milestone Nov 8, 2019
@jeherve jeherve added the [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Nov 8, 2019
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review, this one kinda fell through the cracks.

@jeherve jeherve added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Nov 20, 2019
@jeffersonrabb jeffersonrabb force-pushed the add/amp-block-amp-without-srcdoc branch from dd6f3fd to d9492d1 Compare November 21, 2019 04:54
@jeffersonrabb
Copy link
Contributor Author

Rebased.

@jeffersonrabb jeffersonrabb added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Nov 21, 2019
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello jeffersonrabb! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D35755-code before merging this PR. Thank you!

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work well overall, but I'm getting the following JS error when viewing maps on non-AMP views now:

mapbox-gl.1382b28d502145eaee66.js:formatted:28909 Uncaught TypeError: Cannot read property 'off' of undefined
    at Fi.onRemove (mapbox-gl.1382b28d502145eaee66.js:formatted:28909)
    at n.removeControl (mapbox-gl.1382b28d502145eaee66.js:formatted:28172)
    at t.setBoundsByMarkers (view.js?ver=1574345509:1)
    at view.js?ver=1574345509:1
    at e (lodash.min.js?ver=4.17.15:68)
    at o (lodash.min.js?ver=4.17.15:68)
    at i (lodash.min.js?ver=4.17.15:68)
Fi.onRemove @ mapbox-gl.1382b28d502145eaee66.js:formatted:28909
n.removeControl @ mapbox-gl.1382b28d502145eaee66.js:formatted:28172
(anonymous) @ view.js?ver=1574345509:1
(anonymous) @ view.js?ver=1574345509:1
e @ lodash.min.js?ver=4.17.15:68
o @ lodash.min.js?ver=4.17.15:68
i @ lodash.min.js?ver=4.17.15:68
setTimeout (async)
bo @ lodash.min.js?ver=4.17.15:85
f @ lodash.min.js?ver=4.17.15:69

Do you get that one too?

@jeherve jeherve added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Nov 21, 2019
@jeffersonrabb
Copy link
Contributor Author

This seems to work well overall, but I'm getting the following JS error when viewing maps on non-AMP views now:

Hmmm I'm not getting that. Is it possible to take a look at the exact map in question?

@jeherve
Copy link
Member

jeherve commented Nov 22, 2019

I can't seem to reproduce anymore, with the same map I used yesterday. ¯_(ツ)_/¯

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Nov 22, 2019
@jeffersonrabb jeffersonrabb merged commit 0788e1b into master Nov 22, 2019
@jeffersonrabb jeffersonrabb deleted the add/amp-block-amp-without-srcdoc branch November 22, 2019 17:18
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Nov 22, 2019
jeherve added a commit that referenced this pull request Nov 25, 2019
jeherve added a commit that referenced this pull request Nov 25, 2019
* 8.0 Release: running changelog

* Changelog: add #13921

* Changelog: add #13980

* Changelog: add #13905

* Changelog: add #13971

* Changelog: add #13984

* Changelog: add #14009

* Changelog: add #13620

* Remove things that will ship in 7.9.1

* Changelog: add 7.9.1 release (#14044)

* Changelog: add base for 7.9.1 release

* Update release date and post link

* Changelog: add #14066

* Update changelog for 7.9.1

* Changelog: add #13405

* Changelog: add #13841

* Changelog: add #13924

* Changelog: add #13986

* Changelog: add #14010, #14028, #14053, #14055.

* Changelog: add #14054

* Changelog: add #14031

* Changelog: add #14039

* Changelog: add #14050

* Changelog: add #14070

* Changelog: add #14082

* Changelog: add #14084

* Changelog: add #14111

* Changelog: add #13961

* Changelog: add #14047

* Changelog: add #14091

* Changelog: add #14108

* Changelog: add #14121
@jeherve
Copy link
Member

jeherve commented Jan 23, 2020

r202026-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AMP [Block] Map [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants