-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
React and WebComponents #5052
Comments
The primary component strategy for React will never be Web Components. It runs counter to functional paradigm of React by providing a mostly imperative API. It doesn't help solve any of the problems we have building apps. In fact it makes it more difficult. It does little to nothing to solve the integration problem with other libraries. It doesn't have a solid story around server-side rendering. It doesn't help at all for cross-platform environments like React Native because the overhead of implementing a full DOM spec that we're then going to have to side-step anyway. It is unlikely that Facebook will ever use Web Components at scale and therefore unlikely it will be a priority for us. There has been a lot of excitement about Web Components as an interop layer. Mostly unwarranted IMO. However, we like to support our users so we've made a best effort to try to support interop in the edges. We would like to support as much as possible without compromising the API and vision of React itself. It has turned out that the spec is incomplete with regard to things like event delegation and there are still major changes being pushed from various sides, such as Mozilla. What was in Polymer/Chrome is not the final incarnation so we've had to revert some of the support that we already added (e.g. support for event handling in shadow trees). In terms of strategy, we'll go forward with as if it didn't exist and try to improve interop at the React or React-like component layer instead. I've talked with members of other popular UI frameworks and they seem to feel the same. In fact, we probably have a better chance at implementing solid interop in user land. |
Just to recap, there are two types of approaches in terms of how the UI frameworks allows you to build components:
So basically the ones that are relying on the first approach will have to build their frameworks on top of incomplete specs and potentially dangerous ground. Coming back to the interop subject, I have a question: what do you think about wrapping And lastly, can you share some insights on what |
@cosminnicula The key difference is that custom elements (web components) often expose an imperative API. As an example, consider a video tag/element. There are some relatively declarative attributes (like We touched on this a bit in our most recent blog post: http://facebook.github.io/react/blog/2015/10/01/react-render-and-top-level-api.html#object-oriented-updates We try to support interoperability where possible/practical. For web components that support a purely declarative API via HTML attributes, they should already work reasonably well with React. With regards to wrapping React components as custom elements (or vice versa)... Yes, wrapping is the current recommendation for anyone who requires such interoperability. Since the programming models are different, it's hard to have a seamless API that is automatically generated, so our recommendation is that you write the wrapper class by hand (rather than using an automatic wrapper library), but ultimately it's your choice and you should do whatever works for you. It should be possible to wrap any custom element in a React-wrapper for use in a React application, and vice versa. |
@cosminnicula why do you consider an open source project, adopted by many big companies (some competitors to Facebook) to be 'proprietary, non-standard'. The adoption of the two technologies, might hint at which one of them solves the real world problems better. |
@borisyankov simply because React's one-way data flow and component model will never converge towards W3C I really think that React is solving two important problems which ultimately drives adoption: DOM performance and code complexity. However, |
@cosminnicula That's a misconception. WebComponents in Accelerated Mobile Pages is the SLOW path. It is deferred until the last possible point. It is intentionally the opposite of giving them a performance boost. It is to make everything else isolated. At best it could be the interop layer where you start your component, however, once you're inside the Web Component it is still as slow as the DOM and React will be faster inside of it. It doesn't mean React should render Web Components as its output. Potentially only placeholders for server-side rendering into a AMP document. |
+1 |
mark |
@majorye if your intent was to get notifications there's a subscribe button in the top right of each issue. |
+1 |
We have merged some docs on using Web Components within React: http://facebook.github.io/react/docs/webcomponents.html Those docs, combined with our posts in this issue, is roughly all we have to say on this topic at the moment. Unless there are further questions, I think we can close out this issue. |
Related, we have a wrapper that can convert a web component into a React component: https://github.com/webcomponents/react-integration so you can use a web component as a first-class citizen within React components. |
|
http://staltz.com/react-could-love-web-components.html React.js Conf 2015 - Andrew Rota, Wayfair: |
skatejs has an interesting opinion on this enclosed in their docs.
It would be interesting to see the React teams opinion on this. |
The way you've worded it, It feels like you're trying to stir up the pot. On Fri., 4 Nov. 2016, 21:33 Adam Thomas, notifications@github.com wrote:
|
Not at all, sorry it came across that way. I myself have no opinion on this and the crowd wisdom doesn't seem to be pointing either way. Its not argument, its debate. |
No worries and I'm overly defensive about when it comes to the two I'm very interested to discuss etc. On Sat., 5 Nov. 2016, 00:51 Adam Thomas, notifications@github.com wrote:
|
I see a lot of questions, blog posts and discussions around
React
andWebComponents
, but none of them are actually an official statement from Facebook that could clarify whether or notReact
will going to implementWebComponents
W3C specs in the future.There are also quite a few GitHub Issues around this subject, like "Enable rendering into shadow roots" #1167, "Allow rendering into a document fragment" #840, "Track upcoming DOM technology upgrades" #2836, "Proof of concept: Shadow DOM support" #1877, "Support for custom DOM elements & attributes" #2746, "Templates?" #2286, "Add naive custom element support" #1249, "Add support in the future for custom elements" #1214 etc.
Nevertheless there are some open-source projects that allows
React
to beWebComponents
-aware, like https://github.com/Wildhoney/Maple.js, https://github.com/wix/react-templates or https://github.com/PixelsCommander/ReactiveElementsAs for
WebComponents
, it seems that the reconciliation betweenHTML Imports
andES6 Modules
is inevitable, thus theHTML Imports
part of the spec might need to change in order to be widely accepted among the open-source community and browser vendors https://bugzilla.mozilla.org/show_bug.cgi?id=877072 Until then, wrapping components and importing them asES6 Modules
is as good as including them in HTML pages and importing them with<link rel="import" />
The
Custom Elements
are more or less about defining new markup that you can interact in the same way as with native HTML elements, allowing you to extend existing native HTML elements and giving you some lifecycle methods. This is already possible withReact
andJSX
, even thoughJSX
's XHTML-like syntax transpiles to JavaScript which ultimately becomes HTML through theVirtual DOM
.Shadow DOM
is hard and in some cases even impossible to be polyfilled. This is the reason whyPolymer
is usingShady DOM
https://www.polymer-project.org/1.0/articles/shadydom.html With the current browser support http://caniuse.com/#feat=shadowdom, adoptingBEM
conventions or even inline styles backed by JavaScript objects, which is whatReact
is doing, remains a viable alternative but still is different fromShadow DOM
.Templates
are really pointless without data binding. Two-way data binding is slow because theObject.observe
polyfill (https://github.com/Polymer/observe-js) is slow. Also, two-way data binding is about code complexity and the fact that the more dependencies you have between between components, the bigger the complexity grows, as opposed to unidirectional data flow.React
's one-way data flow with immutable data structures has the potential to scale and be highly performant, especially if we think about large-scale applications and complex interactions between thousands of entities.Even though the open-source community is looking both at
React
andWebComponents
, in the end the developer experience is what matters most and drives adoption. No doubt standards are having their own place in this.Therefore, my question is: what is
React
's strategy forWebComponents
?@sebmarkbage any thoughts?
The text was updated successfully, but these errors were encountered: