-
Notifications
You must be signed in to change notification settings - Fork 797
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
External Media: Don't append to Coblocks replace button #17493
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
Scheduled Jetpack release: November 10, 2020. E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-17493 Thank you for the great PR description! When this PR is ready for review, please apply the |
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.
- ✔️ It works correctly.
- (Minor) The
.indexOf()
compared to-1
stuff can be replaced with.includes()
in both forms:
> "hamburger".includes("burger")
true
> [1, 10, 15].includes(10)
true
- (Minor) If there isn't a render prop, it crashes when trying to call
.toString()
on null. But probably not an issue since you need a render prop to use<MediaLibrary>
. - ❔ Using
render.toString()
and looking for'coblocks'
in the string seems questionable (brittle, potentially slow), but there aren't a lot of other options.
The coblocks call looks like this:
<MediaUpload
allowedTypes={ [ 'image' ] }
onSelect={ onSelectImage }
value={ props.url }
render={ ( { open } ) => (
<Button
isSmall
isSecondary
onClick={ open }>
{ __( 'Replace Image', 'coblocks' ) }
</Button>
) }
>
</MediaUpload>
So it finds the 'coblocks'
they happen to use in a translation function. But what if they replaced the text with an icon? It would stop working. But there isn't enough information elsewhere to go off of.
- Possibility 1: Change the coblocks call to
<MediaUpload>
to add a prop likecontext="coblocks"
. Doesn't seem likely to happen since it's not our code. - Possibility 2: Go the other direction and make all of our calls to
<MediaUpload>
add aincludeExternalSource={true}
prop. Also, doesn't seem that good.
So I see the shortcomings but I can't really think of anything better. 🤷♂️ .
In my testing with performance.now()
, converting the string to a function and looking for the word 'coblocks' in it took 0.01 milliseconds most of the time, and ~2 milliseconds sometimes.
IE11 doesn't support this. I'm not 100% sure whether we polyfill this or not, that would need to be checked in the repository or the Gutenberg project |
r216518-wpcom |
Fixes #17476.
Changes proposed in this Pull Request:
coblocks
textdomain and doesn't append external media links if it does.Does this pull request change what data or activity we track or use?
No
Testing instructions:
Proposed changelog entry for your changes: