-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Circular References in React Native #1509
Comments
I'm not sure I follow, RandomView is only rendered once? |
Sorry, I wasn't super clear as to where the error occurs. |
I see. Yeah, we need to stop trying to render React elements. cc @gaearon – we talked about this before but then I got a bit confused about what exactly to do in the pretty formatter. |
The problem is that The proper way to check if something is an element is to verify it has a |
So, to be clear, this special handling for React elements should be here. For example: <MyComponent props={{
theme: {
message: <BlueMessage /> /* React element inside an object */
}
}} /> |
But it shouldn't be |
It should be
These are three ways to write the same thing, and JSX is the readable one. |
I started implementing this in jamiebuilds/pretty-format#28 and it got confusing pretty quickly because I was suddenly dealing with elements, instances and test renderer instances and I ended up printing quite deeply and it wasn't really useful. |
I don't quite understand what you were trying to do in that PR. I think maybe you got confused over some part of it. I can implement this tomorrow if you'd like. |
I do not mean that you need to iterate over props and find "hidden children" or something like this. I mean that you need to yank out the logic for printing JSX into the generic If not I would appreciate a test case showing the problem so I can work against it. |
I was simply trying to print React elements using the existing react test renderer plugin – including props and its children. Note that we don't need to change pretty-format itself but only the React plugin. Plugins in pretty-format come with a test function and every object gets tested for a match. If you patch the diff you'll find that it doesn't quite work as intended, I think the problem was nested React children. I'd be happy to see a PR with the proper implementation, though – we can chat tomorrow and I can point out the issues I found. In the meantime I'll close this as a duplicate of #1429. |
I think it comes down to what you want to capture in the snapshot. With DOM, we just capture the result DOM tree. So it should be relatively safe to completely throw away any elements (or replace them with some dummy placeholder) because by this point React won't interpret them anyway (and will warn you about extra meaningless props). In the future however we might allow some props on DOM to accept elements so we probably shouldn't lock ourselves out of supporting that. In native it seems like we render down to I still think pretty printing elements is the right thing to do. When the tree gets deep it usually just means that the component you're snapshotting passes unnecessary props down. For example if ListView didn't blindly forward its props to View they wouldn't end up in the snapshot. So it's the component that needs to be fixed to prevent deep pretty prints, not pretty printer. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm not sure if this is intended behavior that I should post on StackOverflow to find a workaround, or a bug in the very new react native test renderer.
I'm seeing a very strange behavior from my current jest mocks for ListView and RefreshControl. Within the snapshot test, the
wrapping component (which is RandomView in the example I wrote below)ListView is rendered multiple times from the RefreshControl's reference.The resulting snapshot file is here, and you can see that the RandomView is being printed out multiple times, and not being resolved to a Circular reference.
What is the correct solution to this problem? Am I doing something unsupported or just doing something incorrectly?
Mocks:
Component
Test
The text was updated successfully, but these errors were encountered: