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

Snapshots should not contain internal React instances #1429

Closed
gaearon opened this issue Aug 15, 2016 · 6 comments · Fixed by jamiebuilds/pretty-format#29 or #1566
Closed

Snapshots should not contain internal React instances #1429

gaearon opened this issue Aug 15, 2016 · 6 comments · Fixed by jamiebuilds/pretty-format#29 or #1566

Comments

@gaearon
Copy link
Contributor

gaearon commented Aug 15, 2016

Sorry if this is the wrong place to file it.
I changed something internal in React and saw snapshot change on www:

screen shot 2016-08-15 at 16 19 08

These are React internal instances. Oops! How did this happen?

An object passed as a prop contained a reference to React element. That element contained _owner field pointing to an internal React instance. That React instance contains references to all its children recursively.

We should find a way to exclude any React internal instances.
A reasonable heuristic these days may be to exclude any object that has _currentElement property.

@cpojer
Copy link
Member

cpojer commented Aug 15, 2016

I'm assuming you didn't call toJSON()? There isn't anything we can do to guard against this – snapshots can be any serializable data structure.

@gaearon
Copy link
Contributor Author

gaearon commented Aug 15, 2016

I'm assuming you didn't call toJSON()?

I don’t know, how can I check? I just updated React in www and existing snapshot tests failed because they encoded React internal objects.

@gaearon
Copy link
Contributor Author

gaearon commented Aug 15, 2016

I’m not sure why _owner is enumerable on React elements but for now you could check $$typeof and if it’s Symbol(react.element), exclude _owner from the pretty print.

screen shot 2016-08-15 at 16 33 07

@cpojer
Copy link
Member

cpojer commented Aug 15, 2016

How do you think we should print these? Just like any other React component using tag, props and children or should it be <InternalReactElement />?

@gaearon
Copy link
Contributor Author

gaearon commented Aug 15, 2016

To be clear, element itself is fine. It's just that _owner links to an internal object which is necessary for React warnings to show the owner component name. So if you print elements nicely (with JSX syntax) the problem should be avoided altogether. Actually I'm surprised the pretty printer didn't recognise it's dealing with an element.

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants