plumatic / dommy

A tiny ClojureScript DOM manipulation and event library
758 stars 74 forks source link

dommy breaks when Polymer is in use #67

Closed radix closed 9 years ago

radix commented 10 years ago

I have no idea whose fault this is, but I want to file the ticket so it's at least known. Whenever I have polymer enabled in Chrome, (dommy/append! (sel1 :body) "foo") fails, with the following error:

"Don't know how to make node from: #<[object HTMLBodyElement]>"

If I use (sel1 :#mybod) (or some other way to get the body), it works.

Maybe Polymer somehow changes the semantics of "document.body"?

To be specific, I'm only including Polymer's platform/platform.js in order to get this behavior.

radix commented 10 years ago
  1. Verified on firefox as well
  2. I think I've traced it down as far as dommy.template.__GT_document_fragment(document.body) failing, but it's really hard for me to debug it further as I'm not very familiar with protocols and cljs yet.

Unfortunately neither chrome nor firefox are giving a traceback for this error, so it's really hard to track down.

jeluard commented 10 years ago

This might be due to how Polymer handle specially body as opposed to other elements. You probably won't have any issue with other selections (at least I don't here).

body normally has to be manually wrapped, see faq.

radix commented 10 years ago

Sorry I never got back to you on this issue. So, the question is, whose responsibility is this incompatibility? Should Dommy work around it, or should this be filed as a bug against Polymer? Do you have any opinions on that?

jeluard commented 10 years ago

Good question. I don't think polymer will fix that as it's a deliberate trade-off for performance reason (I believe). On the other hand dommycan't reasonably implement a work around specific to polymer.

I guess your best option is not to use dommy to select document.body and relies on good old DOM:

(dommy/append! js/document.body "foo")
cpetzold commented 10 years ago

Hmm, not sure why you're getting that issue as (sel1 :body) should just be expanding to js/document.body: https://github.com/Prismatic/dommy/blob/master/src/dommy/macros.clj#L70

cpetzold commented 10 years ago

Ah sorry, I re-read your initial comment.. the issue is in append!, not sel1: https://github.com/Prismatic/dommy/blob/master/src/dommy/core.cljs#L74

The parent node in append! gets "coerced" to a node with template/->node-like. I wonder if it would be better if it was assumed that the parent is a valid dom node, instead of being looser. I'm not sure if anyone is taking advantage of it anyways..

jeluard commented 10 years ago

I believe this might help understanding the issue. One theory could be that dommy somehow installs its own properties to a polymer wrapped element then later on access the non-wrapped version.

jeluard commented 10 years ago

FYI I got this issue and fixed it by using (.querySelector js/document "body") to select the body.

I don't think there is any other option when using polymer's polyfill as using document.body is not supported.

cpetzold commented 9 years ago

Dommy no longer coerces nodes (see https://github.com/Prismatic/dommy/pull/85), and @jeluard's fix (using the native querySelector for body) seems reasonable for use with polymer.