5

I'm torturing myself for hours now and can't find an answer. Where exactly, under what object/key, the React data are located? I found an object ReactRoot that seems to store all the information about components, but I have no idea where it sits in the window (I guess?) object.

It has to be somewhere under the window object, right?

If you take a memory snapshot and select the ReactRoot constructor from the list, chrome will create a reference to it under $0 ($0 in chrome).

EDIT

Is it possible that ReactRoot is declared in a way that makes it inaccessible for other objects? How is this possible in js? React isn't getting any special treatment from the browsers, is he?

platinum_ar
  • 127
  • 3
  • 8
  • 2
    I know almost nothing about react but consider the possibility that it can be declared in a local/function scope that is inaccessible from outside. The may not be a path from the global object. – Wendelin Dec 01 '19 at 00:08
  • 1
    Why would it need to be under the window object? It’s maintained by React. It *could* be on the window, but that would risk inappropriate access so it seems unlikely. – Dave Newton Dec 01 '19 at 00:10
  • the question is: what do you want to do with those objects? They are part of the react rendering machinery and more or less private – Jochen Bedersdorfer Dec 01 '19 at 00:44
  • Wait, are you trying to say that a js script can allocate memory in a magical place where no other outer object has access? I don't want to do anything with it, I'm just a curious person. – platinum_ar Dec 01 '19 at 13:47
  • @platinum_ar That's just what all closures do, yes. – Bergi Dec 01 '19 at 13:58
  • Sorry but this doesn't add up. If closure is a function in a function and that inner function cannot be accessed from the outside then what's the outer function for ReactRoot? Everyware I look, there is a window object at the top: https://medium.com/@fknussel/dom-bom-revisited-cf6124e2a816#5dfd – platinum_ar Dec 01 '19 at 15:26
  • 3
    @platinum_ar That sentence "*The window object is the very root element, everything else is attached to it either directly or indirectly.*" is just plain wrong. (As is, btw, that "*there are no official standards for the BOM*"). Also it's pretty unclear what they mean by "attached". – Bergi Dec 01 '19 at 16:20
  • Its stored in Browser memory, client location. – haaris shamim Nov 02 '20 at 15:39

1 Answers1

-4

There is a document explaining the DOM Level 1 fundamental methods. See also the DOM Level 1 Core specification from the W3C.

When you create an element, a new instance of the element were created but not rendered. Not until you include them into the DOM tree.

Browser will only render elements within the document body. But everything else is just an instance of an object, the virtual DOM.

// create a new Text node for the second paragraph
    var newText = document.createTextNode("This is the second paragraph.");
    // create a new Element to be the second paragraph
    var newElement = document.createElement("P");
Nik
  • 709
  • 4
  • 22