Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix initial render of the embed block when loading a saved post
  • Loading branch information
notnownikki committed Jun 1, 2017
commit 6fea1e8e6976c94b3d78caf20b618b3b8795e102
8 changes: 7 additions & 1 deletion blocks/library/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ registerBlock( 'core/embed', {
this.noPreview = [
'facebook.com',
];
if ( this.props.attributes.url ) {
// if the url is already there, we're loading a saved block, so we need to render
this.doServerSideRender();
}
}

doServerSideRender( event ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we extract this ServerSideRender to a HoC? Maybe something like:

<ServerSideBlock blockType={ blockType } arguments={ arguments }>
  { ( html, error ) => (
    <Sandbox html={ html } /> 
  ) }
</ServerSideBlock>

Any blocker to achieve this?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only blocker is I need to read more React docs to figure out how to do it. There were async issues with having Sandbox as the containing block, this seems like a much better way, I've just never done it before.

Copy link
Contributor

Choose a reason for hiding this comment

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

event.preventDefault();
if ( event ) {
event.preventDefault();
}
const { url } = this.props.attributes;
const api_url = wpApiSettings.root + 'oembed/1.0/proxy?url=' + encodeURIComponent( url ) + '&_wpnonce=' + wpApiSettings.nonce; // eslint-disable-line no-undef

Expand Down