WebReflection / hyperHTML

A Fast & Light Virtual DOM Alternative
ISC License
3.06k stars 112 forks source link

Connection observing does not work inside iframes #339

Closed atirip closed 5 years ago

atirip commented 5 years ago

Why, this is pretty obvious - startObserving() is called only for the first node with ownerDocument that this node may have. I do realize that this issue of mine may ever be only my issue. What I do is I create iframes dynamically and document.write the contents in, then bind stuff to body. So, I could try to modify the code and to start observing for all the different ownerDocuments I may encounter (a lot). I would just appreciate quick reply if this could be doable without some nasty side effects?

WebReflection commented 5 years ago

you should simply write a script that points to hyperHTML and bind that hyperHTML created for that realm/window/document

atirip commented 5 years ago

Mhm, that is the hard solution I tried to avoid, as now I just import hyperHTML, but that way I need to pass (creating hyperHTML for every iframe is easy) that reference to every object that renders.

WebReflection commented 5 years ago

the only (currently) unsupported thing at this point is that nodes with connected and disconnected events won't work as expected. If that's not an issue, you can just bind foreigner bodies, 'cause that's done already in my Shadow DOM light poly https://github.com/WebReflection/attachshadow

would that be enough ?

atirip commented 5 years ago

Found solution, I guess, at least my code started working as expected. Inside wire() all nodes are created for current document and therefore all share same ownerDocument, they get added, but no observer for iframes is created yet. I do need to modify disconnect()this way:

        var documents = new WeakSet();
        return function observe(node) {
            if (!documents.has(node.ownerDocument)) {
                documents.add(node.ownerDocument);
                startObserving(node.ownerDocument);
            }
            observer.add(node);
            return node;
        };

And then call:

        observe(context.ownerDocument.documentElement);

inside bind() which crerates observer, this is safe as I do only bind to bodies. No problem. I can live with that as of now. I have some other my own modifications anyway. Thanks.

WebReflection commented 5 years ago

why don't you file PRs instead?

atirip commented 5 years ago

If you think that is ok, then yes, I will. But I do think that this is just unnessesary code for the 99.99%.