-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
I discussed this with @youknowriad on Slack, but wanted to put it into an issue too.
The current server side rendering is problematic not as nice as it could be. If we have a block that gets a URL from the user, and does some rendering server side to embed the content in a post, we have to duplicate that rendering in the editor block too. We're doing the same work twice, without guarantee that the renders will match, and someone could easily update one and not the other.
My suggestion is to have an API endpoint that takes the required input (in the case of twitter - the URL of the tweet), and returns the rendered HTML from the server side render (which in the case of twitter, WordPress' oembed already does for us).
That way, we could simply send a twitter URL to the endpoint, and have the HTML for embedding it returned. And we only have one bit of code doing that transform from URL to embed HTML.
Additionally, sometimes we want to sandbox some things in iframes, so that javascript or form submissions or stylesheets don't affect the editor.
This is where we could use the Sandbox element (included in the twitter block PR #754 ).
The Sandbox element takes some HTML and puts it in an iframe, and makes sure any script elements in the HTML get run. This works really well for the twitter embeds, as we need to load and run javascript from twitter, but do not want it running in the same context as our editor.
Blocks that use this server side rendering mechanism would be able to flag if the returned HTML gets sandboxed or not.
This opens up the possibility of extending the Embed block so that it can do everything that WordPress oembed can do, very easily.
It would also lets us do pretty much anything a shortcode can currently do, with minimal work. We'd produce a UI asking for the same inputs the shortcode has, constuct the shortcode as a string, send it to the rendering API, and get back the HTML, all ready to go.
The saved content of these blocks would vary. In the case of the twitter block, or a shortcode-based block, it would save the content to be processed by WordPress when the post is rendered. In the case of other blocks where WordPress does not automatically process the content, it would save the HTML returned by the API.
If we get this in place, we could automate generating the base of blocks that work with shortcodes, and could add many many blocks very quickly.