-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Chrome: Adding a ResponsiveImage component to wrap the featured image #911
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be tabs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool 👍 So to be clear, neither the done nor fail case are invoked when the request is aborted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, I tested once but Let me test against to be absolutely certain :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @aduth the abort was being triggered :( So, now I'm ignoring aborted request in the fail callback.
c1c18e0 to
dda7322
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike acronyms, especially e, because it takes me a moment to distinguish intent between the event and error common use-cases. I'm always happier with the verbose equivalent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make Andrew Happy 🙂. You're absolutely right, this is a bad habit of mine
b26b340 to
2a872d7
Compare
| .fail( () => { | ||
| if ( this.props.featuredImageId !== mediaIdToLoad ) { | ||
| .fail( ( error ) => { | ||
| if ( error && error.statusText === 'abort' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking to the docs, the first argument is not the error, but the jqXHR instance:
http://api.jquery.com/jQuery.ajax/#jqXHR
Is it ever falsey?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
components/responsive-image/index.js
Outdated
| return ( | ||
| <div className="components-responsive-image"> | ||
| <div style={ imageStyle } /> | ||
| <img src={ src } className="components-responsive-image__image" alt={ alt } /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, or perhaps even now, we may want to make this component a bit more generic as a responsive panel. The padding technique is rarely used with images, except in this case where we don't know the rendered width, and often more for background images or video elements. It could also help avoid the need to overwhelm the props with individual img attributes we want to assign, if we instead accepted the img as a child.
Not too concerned about this being addressed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to handle this, I've renamed ResponsiveImage as ResponsiveWrapper and it works by checking that the children is a single React Element and then cloning the element to add the class name. Does this sound good for you?
2765064 to
2d054a6
Compare
|
Rebased here. @aduth do you have time to look at this again? |
| import './style.scss'; | ||
|
|
||
| function ResponsiveWrapper( { naturalWidth, naturalHeight, children } ) { | ||
| if ( ! children || Array.isArray( children ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't want to test children as an array, but rather Children.count > 1
https://facebook.github.io/react/docs/react-api.html#react.children.count
Or even Children.only if we don't mind being very noisy (thrown errors) with incorrect usage:
https://facebook.github.io/react/docs/react-api.html#react.children.only
aduth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great 👍
props @aduth
addresses #894 (comment)