-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try: Preact #2734
Try: Preact #2734
Conversation
The two differences are: - Uses el.getDOMNode instead of ReactDOM.findDOMNode. - Doesn't inline the `ref` function within `render`, but binds a proper method to the instance.
@mtias Nice to see this PR, I've been playing around with React on some projects and impressed with its lightweight, performant approach and overall philosophy. I gave the PR a test and it looks like some issues have been worked out, but I had trouble getting past issues with the popover - any hints on how to work on fixing that? I didn't understand your reference to "Popover ref allocation with slot/fill.". In regard to |
@adamsilverstein, I had a go at this yesterday. Haven't fixed it yet, but the gist seems to be that slight differences in the render lifecycle between React and Preact mean that the refs for the elements within the |
Yes, forgot to reference the PR over there. :) |
Fun! Thats a good lead, I'll see if I can figure out why that is happening - that also explains why the popup sort of works the second time you try it. |
id={ id + '-toolbar' } | ||
ref={ ref => this.ref = ref } | ||
className="freeform-toolbar" | ||
/>, |
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.
Comma here will be output as a string.
return [ | ||
controls, | ||
<div key="audio"> | ||
return ( |
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.
While it means we can't treat edit
as a component proper (i.e. assigned as class extends Component
, which we don't support well for save
anyways), I think we could still potentially support array returns by wrapping the return value from the function from the block rendering handler. That or if we identify common characteristics of a block "container", we could create a wrapper component like <Block>
for the block implementer to use.
@@ -6,7 +6,7 @@ import { pick, noop } from 'lodash'; | |||
/** | |||
* WordPress dependencies | |||
*/ | |||
import { Component } from '@wordpress/element'; | |||
import { Component, Children } from '@wordpress/element'; |
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.
Can we avoid the Children
utility and instead leverage the fact that children
is an array in Preact, i.e.
// Before:
Children.only( this.props.children );
// After:
this.props.children[ 0 ];
I think it would be good if we avoid Children
altogether.
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.
That's the exact same thing, the inner implementation is the same, but I can see that this enables to drop preact-compat
at some moment.
return [ | ||
focus && ( | ||
<BlockControls key="controls"> | ||
return <div> |
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.
For consistency, should this be parenthesis-wrapped?
@@ -1,27 +1,22 @@ | |||
/** | |||
* External dependencies | |||
*/ | |||
import { noop } from 'lodash'; | |||
import { Slot } from 'react-slot-fill'; | |||
|
|||
/** | |||
* WordPress dependencies | |||
*/ | |||
import { Component } from '@wordpress/element'; | |||
|
|||
class PopoverProvider extends Component { |
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.
Without context, this doesn't need to be a component class. I also don't think it needs to be a provider in the sense of having children, but rather a slot rendered directly in the layout component. Something like: <PopoverSlot />
.
react: 'preact-compat', | ||
'react-dom': 'preact-compat', | ||
// Not necessary unless you consume a module using `createClass` | ||
'create-react-class': 'preact-compat/lib/create-react-class', |
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.
Is this needed for the components we're using?
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 might be needed for the react libraries we're using but yeah we could try to remove it and see
@@ -2,7 +2,7 @@ | |||
* External dependencies | |||
*/ | |||
import { createElement, Component, cloneElement, Children } from 'react'; | |||
import { render, findDOMNode, unstable_createPortal } from 'react-dom'; // eslint-disable-line camelcase | |||
import { render, findDOMNode } from 'react-dom'; // eslint-disable-line camelcase | |||
import { renderToStaticMarkup } from 'react-dom/server'; |
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.
We should replace this with preact-render-to-string
This turned out to be very useful when exploring if we can replace React with Preact. It is no longer up to date so I'm closing it. |
(Converting to pull request for better visibility.)
This explores using preact as the primitive powering the rendering mechanism of Gutenberg.
Known issues:
edit
declarations).ref
allocation with slot/fill.componentDidCatch
alternative. Support for componentDidCatch preactjs/preact#799