brentd / xray-rails

☠️ A development tool that reveals your UI's bones
MIT License
1.22k stars 79 forks source link

Xray's comments interfere with ajax interpretation #22

Closed skwp closed 11 years ago

skwp commented 11 years ago

Our server is returning a snippet of html which jquery is parsing. When xray is turned on, the response looks like this:

<!--XRAY START 118 /Users/yan/dev/reverb/app/views/products/_question.html.erb-->
<li>
<div>some html</div>
</li>
<!--XRAY END 118-->

It seems this causes an error in jquery 1.8 and possibly later versions while parsing the XHR response:

Uncaught TypeError: Cannot use 'in' operator to search for 'backgroundColor' in undefined 

I'm not sure what to do about it yet, but if we figure it out, we'll submit a pull request.

brentd commented 11 years ago

Hmm. That's super sad, and odd. I'm sure I'm rendering a partial from an XHR response in at least one application, and haven't experienced this. If I get a chance I'll do some testing.

skwp commented 11 years ago

Yeah, I'm wondering if it's something about the number in there that's making it freak out.

brentd commented 11 years ago

Trying to duplicate this tonight because I had another report of this happening. I wish I could say I was successful.

@skwp could you pull down the gh-22-xhr-requests branch, run rake server to start the dummy app, and tell me if you can edit the views to make this break? Here's where the XHR is happening:

https://github.com/brentd/xray-rails/blob/gh-22-xhr-requests/spec/dummy/app/views/application/root.html.erb

skwp commented 11 years ago

Sorry I didn't see your comment. I'll try to reproduce with the latest version. Do you think it's fixed in this commit?

brentd commented 11 years ago

Nope, no fix yet.

I think I may have a slightly better idea of what's going on though. The XHR itself isn't the problem - it's probably that certain jQuery operations on a set starting with an HTML comment will fail if they expect the first element in the set to be, well... not a comment node.

You should be able to test this theory in your code if you use $(html).filter('*') where html is the XHR's response string. That will return a new jQuery set without any junk, like xray's comments.

If that makes your code work, I'll have to seriously consider implementing #24 in some fashion.

brentd commented 11 years ago

No further feedback on this, so I'm closing, but know that I'm going to implement an alternative to the xray comments very soon that should take care of this isuse for good.

redesigned commented 10 years ago

When x-ray is enabled in chrome prototype ajax is breaking for me. Disabling it resolves the issue.