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

✨ Proof of concept React BaseElement #24153

Closed
wants to merge 4 commits into from

Conversation

jridgewell
Copy link
Contributor

This is a proof of concept to support React/Preact Components in AMP pages. Once we flesh this out, we can provide a generic class factory to create AMP.BaseElement classes for each wrapped Component, which can then be registered and used like regular AMP components.

A lot of the hard work was already done in <amp-date-picker>.

* @return {*}
*/
render() {
const props = pick(this.props, ATTRIBUTES_TO_PROPAGATE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these not camel-cased?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a local binding at the top of the array.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant: are the attributes->props camel-cased? I.e. should it be "aria-label" or "ariaLabel"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Playing around, it appears to work either way... I'm not sure. aria-label should definitely be lowercase, though: https://reactjs.org/docs/dom-elements.html.

constructor(props) {
super(props);

this.state = {prerender: true};
Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely subject to bikeshedding, but imho, this should be something like "loading=auto|manual", since there might be other reasons to block rendering, besides prerendering.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, I'm not tied to prerender at all, it just the first name I thought of.

extensions/amp-react-img/0.1/amp-react-img.js Outdated Show resolved Hide resolved
extensions/amp-react-img/0.1/amp-react-img.js Outdated Show resolved Hide resolved
extensions/amp-react-img/0.1/amp-react-img.js Outdated Show resolved Hide resolved
props['decoding'] = 'async';

const {prerender} = this.state;
if (prerender && !this.prerenderAllowed_) {

Choose a reason for hiding this comment

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

I'm curious, why is this.state. prerender and this.prerenderAllowed_ needed? Why not directly check the prop value for noprerender to determine if src and srcset should be deleted?

if (!this.props.noprerender) {
  delete props['src'];
  delete props['srcset'];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi!

I think we actually meant to do !prerender || !this.prerenderAllowed. Note that we have to different sources here, one from this.state.prerender (which is outside-of-React props being passed to React) and props.noprerender (which is both the DOM-React and React-React possible values). We use the state to control from the AMP framework, and props to allow the publisher to control behavior.

Also, this PR is stagnant. We started a new attempt at #25969. Feel free to follow along!

Choose a reason for hiding this comment

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

Thanks for the info!

@jridgewell jridgewell closed this Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants