thanhlong203 / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

Error in in goog.style.getBoundingClientRect_ if parent is not present #224

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I am getting auto error reports with the following item at the top of the stack:

message[setting a property that has only a getter] 
url[http://myurl/scripts/myscript.min.js] 
line[95] 
browser[Netscape : 5.0 (Windows; es-ES)] 
stack[
  $goog$style$getBoundingClientRect_$$([object HTMLDocument])    
    @http://myurl/scripts/myscript.min.js:95
  $goog$style$getClientPosition$$([object HTMLAnchorElement])
    @http://myurl/scripts/myscript.min.js:99 
  ... (Internal code)]

The browser[type : version] is gathered using this script:
navigator.appName + ' : ' + navigator.appVersion

I had a quick look through the code and I could not find anything obvious.  A 
quick search turns up FireBug related issues in FF3.6 but again I could not 
reproduce in my dev environment.  

Is there anything I can add to my error report that will help in identifying 
this issue?  More navigator information?

Thanks

Guido Tapia

Original issue reported on code.google.com by guido.tapia@gmail.com on 24 Oct 2010 at 8:40

GoogleCodeExporter commented 8 years ago
What I see is the argument passed to goog.style.getBoundingClientRect_ is a 
document, not an element. Does it help debugging the issue?

Does the same error happen if the code isn't compiled?

Original comment by pall...@gmail.com on 25 Oct 2010 at 12:55

GoogleCodeExporter commented 8 years ago
Unfortunately I cannot reproduce the error in compiled or uncompiled mode.  
This is just what I'm getting periodically via an auto-report mechanism on my 
script.

From the stacktrace above you can see that I call goog.style.getClientPosition 
with an anchor element.  So the bug must be with 'goog.style.getClientPosition' 
which then calls goog.style.getBoundingClientRect_ with the document element.

Original comment by guido.tapia@gmail.com on 26 Oct 2010 at 3:13

GoogleCodeExporter commented 8 years ago
The first few lines of goog.style.getClientPosition:

goog.style.getClientPosition = function(el) {
  var pos = new goog.math.Coordinate;
  if (el.nodeType == goog.dom.NodeType.ELEMENT) {
    if (el.getBoundingClientRect) {  // IE and Gecko 1.9+
      var box = goog.style.getBoundingClientRect_(/** @type {Element} */ (el));

According to this code it is impossible that the 'el' argument becomes a 
document before getBoundingClientRect_ is called.

If it is indeed replaced with a document, the replacement must be done outside 
Closure.

I'm marking this as WontFix until someone can reproduce the bug.

Original comment by pall...@google.com on 26 Oct 2010 at 9:23

GoogleCodeExporter commented 8 years ago
I found the issue.  If an element becomes detached from its parent and then u 
call goog.style.getClientPosition then this problem occurs (only in IE) other 
browsers return {0, 0}.  I have implemented a fix (patch attached) that I think 
is performant but please review carefully as my knowledge of DOM and quirks in 
different browsers is not great.

Thanks 

Guido Tapia

Original comment by guido.tapia@gmail.com on 31 Oct 2010 at 11:26

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the investigation, I reopened the bug.

Original comment by pall...@google.com on 1 Nov 2010 at 1:48

GoogleCodeExporter commented 8 years ago

Original comment by nn...@google.com on 27 Apr 2012 at 9:53