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

Refactor how composite type changes work, fix memory leak in ReactMount caching #4983

Merged
merged 5 commits into from Oct 7, 2015

Conversation

Projects
None yet
4 participants
@sophiebits
Copy link
Collaborator

commented Sep 26, 2015

No description provided.

@sophiebits

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 26, 2015

@sebmarkbage A nice bug fix and some small steps towards not using hierarchical IDs. This should let us try out createElement again.

sophiebits added a commit to sophiebits/react that referenced this pull request Sep 27, 2015

Walk down internal tree to find DOM node
This reduces our reliance on hierarchical IDs. If facebook#4983 merges, this can look at `._nativeNode` when present.

@sophiebits sophiebits force-pushed the sophiebits:id-swap branch from fc5582d to d42b971 Sep 28, 2015

sophiebits added a commit to sophiebits/react that referenced this pull request Sep 28, 2015

Walk down internal tree to find DOM node
This reduces our reliance on hierarchical IDs. If facebook#4983 merges, this can look at `._nativeNode` when present.

sophiebits added a commit to sophiebits/react that referenced this pull request Sep 28, 2015

Walk down internal tree to find DOM node
This reduces our reliance on hierarchical IDs. If facebook#4983 merges, this can look at `._nativeNode` when present.
@@ -164,10 +175,11 @@ function setID(node, id) {
* @internal
*/
function getNode(id) {
if (!nodeCache.hasOwnProperty(id) || !isValid(nodeCache[id], id)) {
nodeCache[id] = ReactMount.findReactNodeByID(id);
if (nodeCache.hasOwnProperty(id)) {

This comment has been minimized.

Copy link
@jimfb

jimfb Sep 28, 2015

Contributor

Maybe:

var node = getNodeIfCached(id);
if(node) return node;
else return nodeCache[id] = ReactMount.findReactNodeByID(id);

At the very least that saves an object lookup (object lookups are surprisingly expensive in javascript). It also reads a little better IMO.

This comment has been minimized.

Copy link
@sophiebits

sophiebits Sep 28, 2015

Author Collaborator

Yeah sure. I was mostly keeping it how it was.

@sophiebits sophiebits force-pushed the sophiebits:id-swap branch from d42b971 to e1a127b Sep 28, 2015

@jimfb

This comment has been minimized.

Copy link
Contributor

commented Sep 28, 2015

Squash and ship! (at least, I have no objection :) )

@sebmarkbage sebmarkbage added this to the 0.15 milestone Sep 29, 2015

@sebmarkbage

This comment has been minimized.

Copy link
Member

commented Sep 29, 2015

Too much for 0.14 unless it fixes a new regression.

@sophiebits

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 29, 2015

Yeah, wasn't going to do it in 0.14. Also was planning to leave the commits separate since they're separate things.

sophiebits added some commits Sep 26, 2015

Cache native node on native components, return it when unmounting
This is probably slightly slower for unmounts in the case that no updates were ever performed, but caching the node on the instance should make updates faster. In any case, the more important consequence of this change is that we can fix the current memory leak that happens when swapping composite types.
Use returned native node for composite type-change
With this change, all unmounted components should be properly purged from ReactMount's cache.
Don't use existing "root" ID if non-root
Before, if you had

```
container = <div data-reactid=".0"><div data-reactid=".0.0" /></div>;
```

and did `ReactDOM.render(<span />, container)` you would get

```
<div data-reactid=".0"><span data-reactid=".0" /></div>;
```

(along with a warning not to replace React-rendered children with a new tree like that). But that makes no sense -- the span should have a new index, not truncate the ID of the old child it's replacing.

(Now tests pass again with useCreateElement on; before they threw a "valid but unequal" on our test for this warning.)
ReactMount now never expects invalid nodes in its cache
It never really made sense for us to have "invalid" nodes in the cache -- when we unmount things, we should always remove them from the cache properly. Now that swapping composite types doesn't repopulate the cache, we should be okay to now assume that everything in the cache is good.

@sophiebits sophiebits force-pushed the sophiebits:id-swap branch from 801c910 to 8ce7b71 Oct 7, 2015

sophiebits added a commit that referenced this pull request Oct 7, 2015

Merge pull request #4983 from spicyj/id-swap
Refactor how composite type changes work, fix memory leak in ReactMount caching

@sophiebits sophiebits merged commit f31a46c into facebook:master Oct 7, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

sophiebits added a commit to sophiebits/react that referenced this pull request Oct 7, 2015

Walk down internal tree to find DOM node
This reduces our reliance on hierarchical IDs. If facebook#4983 merges, this can look at `._nativeNode` when present.

sophiebits added a commit to sophiebits/react that referenced this pull request Oct 7, 2015

Walk down internal tree to find DOM node
This reduces our reliance on hierarchical IDs. If facebook#4983 merges, this can look at `._nativeNode` when present.

@renovate renovate bot referenced this pull request Feb 2, 2018

Open

Update dependency react to v0.14.9 #29

0 of 1 task complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.