Skip to content

Conversation

@dreamofabear
Copy link
Collaborator

@dreamofabear dreamofabear commented Sep 20, 2016

A simple React-based progressive web app that displays Accelerated Mobile Page (AMP) content. Built on create-react-app for minimal build configuration.

Live demo: http://choumx.github.io/amp-pwa

This project adds modern web features to create-react-app:

  • Accelerated mobile page (AMP) content: Displays fast-loading AMP documents within the app shell via Shadow DOM.
  • Progressive web: A service worker enables progressive enhancement of AMP content with precaching, offline functionality and an app shell.

Compared to create-react-app, this project adds a small number of new dependencies:

  • sw-precache generates a production-ready service worker for precaching and other progressive enhancements.
  • express is used to run the development API server, server.js.
  • bootstrap and react-bootstrap can be easily removed for your choice of UI framework.

@dreamofabear
Copy link
Collaborator Author

@cramforce PTAL

@cramforce cramforce changed the title Add amp-pwa source A react based PWA for displaying AMP content Sep 20, 2016
Copy link
Member

@cramforce cramforce left a comment

Choose a reason for hiding this comment

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

I'm getting lots of AMP related errors in the console. Is that expected? @dvoytenko

"type": "image/png"
}
]
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

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

Add trailing newlines here and elsewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

}
Home.propTypes = {
documents: React.PropTypes.arrayOf(React.PropTypes.object),
}
Copy link
Member

Choose a reason for hiding this comment

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

; :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@sebastianbenz
Copy link
Collaborator

The demo doesn't work on safari - if this is intended, we should mention it in the limitations.

@cramforce
Copy link
Member

Could you fix the images?

When I'm going to a deep link directly it serves the AMP doc (yaihh), but then SW installation fails with a 404.

@dvoytenko
Copy link
Contributor

@cramforce I noticed errors yesterday and fixed in a separate PR. Unfortunately, this part broken on resources refactoring. We'll need to setup integration tests for this part.

@dreamofabear
Copy link
Collaborator Author

dreamofabear commented Sep 21, 2016

The demo doesn't work on safari - if this is intended, we should mention it in the limitations.

@sebastianbenz Not intended -- I'm investigating a problem in Safari with the Closure-compiled version of the AMP-shadow runtime, shadow-v0.js. My latest build bundles the uncompiled version via Webpack and it works in Safari: http://choumx.github.io/amp-pwa

Could you fix the images?

Done. I also worked around the shadow bug by bundling a local build, although it breaks amp-social-share and amp-list due to version mismatch with extensions. It works better than before, though hopefully everything will work in the next prod push.

When I'm going to a deep link directly it serves the AMP doc (yaihh), but then SW installation fails with a 404.

That was probably the amp-install-serviceworker extension in each content page. I've removed those as well as some unnecessary UI.

@dreamofabear dreamofabear changed the title A react based PWA for displaying AMP content A React-based PWA for displaying AMP content Sep 21, 2016
@cramforce
Copy link
Member

Can you make URLs like
https://choumx.github.io/amp-pwa/content/housing.amp.html hit the SW and
load the shell when they get loaded with SW installed?

On Tue, Sep 20, 2016 at 5:28 PM, William Chou [email protected]
wrote:

The demo doesn't work on safari - if this is intended, we should mention
it in the limitations.

@sebastianbenz https://github.com/sebastianbenz Not intended -- I'm
investigating a problem in Safari with the minimized version of the
AMP-shadow runtime, shadow-v0.js. My latest build bundles the unminimized
version via Webpack and it works in Safari: http://choumx.github.io/amp-
pwa

Could you fix the images?

Done. I also worked around the shadow bug by bundling a local build,
although it breaks amp-social-share and amp-list due to version mismatch
with extensions. It works better than before, though hopefully everything
will work in the next prod push.

When I'm going to a deep link directly it serves the AMP doc (yaihh), but
then SW installation fails with a 404.

That was probably the amp-install-serviceworker extension in each content
page. I've removed those as well as some unnecessary UI.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#52 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFeT48C7FREJMOMTn6q530KUPdyoiLvks5qsHo6gaJpZM4KCALB
.

@dreamofabear
Copy link
Collaborator Author

That should already work and I just tested it again on desktop Chrome. If you see the nav bar at the top, then the shell was rendered.

@cramforce
Copy link
Member

Yeah, never mind. It is working now.

On Wed, Sep 21, 2016 at 11:07 AM, William Chou [email protected]
wrote:

That should already work and I just tested it again on desktop Chrome. If
you see the nav bar at the top, then the shell was rendered.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#52 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFeT5xP46tAF1lRUZvaCYt4V1l5FQq3ks5qsUg7gaJpZM4KCALB
.

@cramforce
Copy link
Member

One request, though: The leaf pages should use amp-install-serviceworker to
bootstrap the app.

On Wed, Sep 21, 2016 at 11:09 AM, Malte Ubl [email protected] wrote:

Yeah, never mind. It is working now.

On Wed, Sep 21, 2016 at 11:07 AM, William Chou [email protected]
wrote:

That should already work and I just tested it again on desktop Chrome. If
you see the nav bar at the top, then the shell was rendered.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#52 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFeT5xP46tAF1lRUZvaCYt4V1l5FQq3ks5qsUg7gaJpZM4KCALB
.

@sebastianbenz
Copy link
Collaborator

Few more comments from my side:

  • the link to the homepage is not working (amp-pwa) is missing
  • can we include cross references between articles to demonstrate how the PWA handles these?
  • I would pick different sample pages:
    • The hello world sample article only shows the AMP icon
    • The live blog sample doesn't work
    • The search in the product sample leads back to ampbyexample.com

@cramforce
Copy link
Member

@sebastianbenz We're looking at actually getting good newsy-content soon. The ABE stuff is just to have something at all.

@dreamofabear
Copy link
Collaborator Author

The leaf pages should use amp-install-serviceworker to
bootstrap the app.

Done.

the link to the homepage is not working (amp-pwa) is missing

Fixed, thanks!

can we include cross references between articles to demonstrate how the PWA handles these?

@sebastianbenz Could you elaborate on what you mean by this? E.g. have the list of articles in the nav bar, or in the AMP documents themselves?

@cramforce
Copy link
Member

cramforce commented Sep 21, 2016

@choumx I think what @sebastianbenz meant is something like this:

<a href="/link/to/article.html">Article</a>

Clicking this should trigger the PWA router and navigate on the client side.

}

componentDidMount() {
this.fetchAndAttachAMPDoc_(this.props.src);
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, we do full camel-case style guide. E.g. fetchAndAttachAmpDoc_. If it doesn't conflict with React - let's switch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.


/**
* `window.AMP` is set by the AMP runtime when it finishes loading.
* @private
Copy link
Contributor

Choose a reason for hiding this comment

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

@const

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.


/**
* Child element that the AMP document will be added as a shadow root to.
* @private
Copy link
Contributor

Choose a reason for hiding this comment

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

Please define type

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.


/**
* XMLHTTPRequest that fetches the AMP document.
* @private
Copy link
Contributor

Choose a reason for hiding this comment

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

type

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

* Fetches and parses HTML at `url`.
* @private
* @param {string} url
* @return {Promise} If fetch succeeds, resolved with {Document}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be {!Promise<!Document>}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

*/
fetchDocument_(url) {
return new Promise((resolve, reject) => {
const xhr = (this.xhr_ = new XMLHttpRequest());
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we also need to reset this.xhr_ = null in the either outcome of this promise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@dreamofabear
Copy link
Collaborator Author

Added cross-ref links to AMP documents and corresponding react-router support in amp-document.js.

Haven't updated the live demo with this yet -- ironically, prod AMP works for this feature but HEAD has issues.

@dvoytenko
Copy link
Contributor

I'm good here. How about everyone else?

@dreamofabear
Copy link
Collaborator Author

@cramforce Any other feedback?

Copy link
Member

@cramforce cramforce left a comment

Choose a reason for hiding this comment

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

Lets merge this and then flesh out details in follow up!

@dreamofabear dreamofabear merged commit ab04d65 into ampproject:master Sep 27, 2016
@dreamofabear dreamofabear deleted the amp-pwa branch September 27, 2016 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants