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
[labs/react] Add Node build #3410
Conversation
🦋 Changeset detectedLatest commit: b67c03a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultslit-element-list
render
update
update-reflect
lit-html-kitchen-sink
render
update
nop-update
lit-html-repeat
render
update
lit-html-template-heavy
render
update
reactive-element-list
render
update
update-reflect
|
I modified it a bit, just in case a user happens to bring in a DOM shim that does define |
This shouldn't be a whatever lands first situation. |
I'm saying the conflict will be easy to resolve whichever gets merged first. This node build is strictly an addition that does not affect existing client side behavior in any way. Here's how a merge of this into your PR with conflicts resolved would look like adde5b8#diff-70e2e47659157c4129a63acfad45aa00d53e5314c322b4acc9e677cb1cbaf97a |
// might not be defined | ||
!(NODE_MODE && typeof HTMLElement === 'undefined' | ||
? false | ||
: k in HTMLElement.prototype) && |
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 feel like this ternary should be able to be done at the module
level.
There should be a way to get the prototype
or false
outside of the ReactComponent.render
function and outside of the createComponent
function?
const SERVER_CHECK = <is node server> ? (Element || SomeShim) : HTMLElement;
then later we can use the appropriate prototype instead of both?
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.
The ternary is potentially run for every property on every render. It should be only called when necessary.
Also the following in-out check disappears in #3128
!(k in HTMLElement.prototype) && ...
So this check might not conflict with the current code, but it does not fit in the proposed changes of #3128 which corrects the behavior these changes are based on.
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.
The location of the code doesn't matter since terser will remove the side of the ternary that doesn't belong based on NODE_MODE
for the "node" and "production" builds. I think it's cleanest if the conditional is close to where HTMLElement
is referenced so we can remove it for the node build. (this part was based on your first comment pre-edit.)element
and HTMLElement
are not the interchangeable part 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.
Regarding #3128, see #3410 (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.
I understand the need for it to be close to the logic. But it's too much happening in an if
statement. It makes it more difficult to read and maintain later on. Accounting for a fallback at the module level is more durable. This is technically a nested if statement except it's nested at the condition statement.
We are if
-ing a prototype and a ternary inside a conditional statement does not read that way to me
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.
element and HTMLElement are not the interchangeable part here.
HTMLElement
is not used in #3128, this is what i mean by conflicts
. Not conflicts as in git i mean conflicts as in implementation and correctness
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.
Was lurking and not very plugged into this, but was reading the source on the branch and this line of code stood out to me.
it's too much happening in an if statement
Agree with Brian on this one. If you're keeping this logic, is there a way to rewrite this without hurting perf? Nested if
I think would be okay here if only for readability
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.
Yup. Now with the reference to HTMLElement
moved to a lifecycle that won't be called on the server, this gnarly condition here won't be necessary. To address prop/attribute handling during server-render, I anticipate it'll be a much more straight forward single if (NODE_MODE)
or if (isServer)
check instead.
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.
see comments
Also, I don't know if making Have we considered an I'd like to leave In the economy, like you pointed out, most developers would bring their own The responsibility for the definition of I think the best approach would be to emulate that in our own server-side space. As in, |
@taylor-vann Appreciate the feedback, and apologies for not looping you in sooner! Per offline discussion, we'll hold on this PR until #3128 goes in, which moves the For future SSR considerations, beyond making it not error, we'll have to look at the output by React's server rendering to consider which attributes should be added to the custom element SSR result, and whether we need to suppress React's own hydration warning for these wrapped custom elements as done in @kevinpschaaf 's early React SSR exploration work here https://github.com/lit/lit/blob/lit-react-ssr-old/packages/labs/ssr/src/lib/react/create-element.ts. I anticipate we'll eventually either need a node build or conditional code with Putting this into draft for now. |
Superseded by #3885 |
Resolves #3397
This adds a Node build for the
@lit-labs/react
package.The Node build version will provide a minimal shim of an emptyHTMLElement
class to thecreateComponent
module, using the same approach asreactive-element
in #3156.The Node build version skips the
in HTMLElement.prototype
ifHTMLElement
is not defined in global. In that case, relying onin element.prototype
would be enough, sinceReactiveElement
would be extending an emptyHTMLElement
class from our Node build shim.This approach will conflict with #3128, but it should just be a matter of moving over the
NODE_MODE
check to whereHTMLElement
reference got moved to. We can coordinate depending on which one gets merged first. cc: @taylor-vann