Skip to content
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

[Embeddable] Seamless React integration #140395

Closed
dokmic opened this issue Sep 9, 2022 · 3 comments · Fixed by #143131
Closed

[Embeddable] Seamless React integration #140395

dokmic opened this issue Sep 9, 2022 · 3 comments · Fixed by #143131
Labels
Feature:Embedding Embedding content via iFrame impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:large Large Level of Effort Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas

Comments

@dokmic
Copy link
Contributor

dokmic commented Sep 9, 2022

Background

The current way of rendering React applications inside an embeddable widget requires the usage of the react-dom library. Because of that, we have a detached Virtual DOM tree per each widget, which may negatively impact performance.
Another downside of this approach is that we are losing the React context, and we have to reinitialize in every implementation (e.g., internationalization and theme). That causes code repetition along with growing technical debt.

Proposal

We can provide seamless integration with React by extending our contract to allow returning React elements in the render function. We can conditionally mount returned React children in the runtime or fall back to the existing approach.

class HelloWorldEmbeddable extends Embeddable {
 render() {
   return <EuiEmptyPrompt body={this.getTitle()} />;
 }
}

Additionally, we can allow third-party applications to return regular DOM nodes that will be appended to the containing node. This change should abstract us from DOM manipulation inside embeddable components.

class HelloWorldEmbeddable extends Embeddable {
 render() {
   const container = document.createElement(‘div’);
   render(<EuiEmptyPrompt body={this.getTitle()} />, container);

   return container;
 }
}

These changes should provide better interaction with React as well as a framework-agnostic way of rendering widgets. This can be done by using methods polymorphism in TypeScript and providing multiple render method overloads. In the base implementation, we can check the method’s returned value and mount that into the existing Virtual DOM tree.

@dokmic dokmic added Feature:Embedding Embedding content via iFrame loe:medium Medium Level of Effort impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. Team:AppServicesUx labels Sep 9, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServicesUx)

@exalate-issue-sync exalate-issue-sync bot added loe:large Large Level of Effort and removed loe:medium Medium Level of Effort labels Sep 9, 2022
@exalate-issue-sync exalate-issue-sync bot reopened this Oct 24, 2022
@petrklapka petrklapka added Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas and removed Team:AppServicesUx labels Dec 12, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@ThomThomson
Copy link
Contributor

Closing this issue again as it was covered in #143131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Embedding Embedding content via iFrame impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:large Large Level of Effort Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants