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

Most components are mounted out of context in the React devtools #16

Closed
darkyen opened this issue Jun 2, 2015 · 4 comments
Closed

Most components are mounted out of context in the React devtools #16

darkyen opened this issue Jun 2, 2015 · 4 comments
Assignees
Milestone

Comments

@darkyen
Copy link

darkyen commented Jun 2, 2015

image

The above is a screenshot when React Inspector was used in chrome devtools, I'd expect the above to look like

<SplitView>
    <Pane>...</Pane>
    <Content>
        <AppCanvas>
           <Locations>
              <Location>
                  <Pivot>
                    <Pivot.Item> 
                       <h1>Hello World</h1>
                    </Pivot.Item>
                  </Pivot>
              </Location
           </Locations>
        </AppCanvas>
    </Content>
</SplitView>

I wonder why most things are uprooted and rendered on top level instead of the react way ?

@rigdern
Copy link
Contributor

rigdern commented Jun 10, 2015

This occurs whenever a ReactWinJS component calls React.render. Whenever a component does this, the content it's rendering ends up appearing at the root of the React inspector.

There are a couple of things to investigate for fixing this:

  1. Is there a way to implement ReactWinJS components without calling React.render?
  2. Will React portals help? Nested Render Trees facebook/react#3210

ReactWinJS components call React.render because they are wrapping WinJS controls which manipulate the DOM directly and are not React components. Whenever a WinJS control can host app content (e.g. ContentDialog, SplitView, Hub, Pivot), the ReactWinJS component will call React.render to enable you to express the hosted content as a React component.

Thanks for the report.

@rigdern rigdern changed the title [question] Why are most components mounted out of context ? Most components are mounted out of context in the React devtools Jun 10, 2015
@darkyen
Copy link
Author

darkyen commented Jun 26, 2015

@rigdern I wrote a smaller binding for winjs with react before we switched to this, init i used to render the winjs components onComponentMounted by calling the constructor and passing the element directly getting it from react, and let winjs handle that task.

Can that approach not be used ?

@rigdern
Copy link
Contributor

rigdern commented Jun 27, 2015

@darkyen I believe we are using the approach you described:

The problem occurs when a WinJS control hosts HTML content and you want to describe that content as a React component. For example, how would you implement the SplitView component such that you can describe the pane as a React component?

Our current implementation will construct the SplitView using the method you described. However, it'll call React.render on the pane component to render it within the SplitView and the pane will end up appearing outside of the SplitView in the React debug tools.

@darkyen
Copy link
Author

darkyen commented Jun 27, 2015

oh okay, i understand the exact cause now.

#Hacky way i made it work (for a completely different reason)
How i did it was to use a hidden node (display: none;) as a wrapper and create 2 copies of the element then write custom code so that split view actually had <SideView> and <ContentView> seperately basically my version was more close to react-art or react-canvas rather than react itself, it used react solely for the purpose of creating elements in winjs

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

No branches or pull requests

5 participants