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

Use ReactDOM.createPortal instead of ReactDOM.render for nested views #138

Merged
merged 1 commit into from
Nov 8, 2018

Conversation

Anber
Copy link
Contributor

@Anber Anber commented Oct 24, 2018

I've noticed that each react view is rendered as a separate React instance. As a result, it's impossible to share react context between views. In this PR I have tried to fix this behavior by using react portals.

@christopherthielen, what do you think about that?

@christopherthielen
Copy link
Member

I love this idea! It would address #3

Let me know how I can help.

@Anber
Copy link
Contributor Author

Anber commented Oct 24, 2018

Maybe you can find some pitfalls that I've missed :)

Anyway, I need to test it in-house for a few days.

@Anber
Copy link
Contributor Author

Anber commented Oct 30, 2018

It seems to be ok.

@Anber Anber changed the title WIP: Use ReactDOM.createPortal instead of ReactDOM.render for nested views Use ReactDOM.createPortal instead of ReactDOM.render for nested views Oct 30, 2018
@christopherthielen
Copy link
Member

Works for me!

@christopherthielen christopherthielen merged commit 58115b9 into ui-router:master Nov 8, 2018
@christopherthielen
Copy link
Member

Released as @uirouter/react-hybrid@0.3.6

@Anber
Copy link
Contributor Author

Anber commented Nov 9, 2018

Thank you!

@christopherthielen
Copy link
Member

No, thank you !

@christopherthielen
Copy link
Member

Here's a summary of how this PR works:

React - <UIView wrap={true} />                             -- monkey patched UIView, has this.setChildViewProps
                                                           -- renders an AngularUIView
                                                           -- renders a react portal if 'target' has been supplied via setChildViewProps
React -  <React.createPortal />                            -- Renders real React UIView
React -  <AngularUIView sCVP={this.setCVP} />              -- creates <ui-view>
AngJS -   <ui-view ref={ref => $compile(ref)}></ui-view>   -- renders react-ui-view-adapter via compile() function 
                                                           -- scope.setChildViewProps = setChildViewProps provides the 'setChildViewProps' callback to AngularJS children (react-ui-view-adapter)
AngJS -    <react-ui-view-adapter></react-ui-view-adapter> -- supplies the portal with a 'target' using 'setChildViewProps', OR renders real React UIView if no setChildViewProps exists because there is no parent PortalView
React -     <UIView wrap={false} />

@christopherthielen
Copy link
Member

christopherthielen commented Nov 15, 2018

Updates: 2b88c57, ab4edcb in version 0.3.8

Summary of changes:

  • Render multiple portals, one for each child UIView
  • Use child UIView $id as a key to manage multiple react portals in PortalView
  • setChildViewProps is now PortalView.createPortalToChildUIView and PortalView.removePortalToChildUIView
  • Pass the PortalView reference to the react-ui-view-adapter (instead of setChildViewProps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants