Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jQuery data is visible only in some stack frames #707

Open
orientalperil opened this issue Nov 21, 2019 · 1 comment
Open

jQuery data is visible only in some stack frames #707

orientalperil opened this issue Nov 21, 2019 · 1 comment

Comments

@orientalperil
Copy link
Contributor

I'm using Annotator from http://annotatorjs.org/ to write a qualitative data analysis (QDA) web application. I want to make some calls into its API. These functions take an annotation object as an argument. The annotation is stored using jQuery's $().data() method on the <span> tags that represent the highlighted text of the annotation. You can access it with code like this:

$('.annotator-hl').map(function (_, elem) {
  return $(elem).data('annotation');
}).toArray()

The issue I'm having is that when I run this code I get an empty array. No data is retrieved at all. I put some breakpoints into the code to inspect deeper and found that in certain stack frames this code returns the correct data and in other stack frames it returns nothing. This is very strange because I don't know of any relation between using $().data() to store data and some functions where that data would be visible or invisible.

I thought I was crazy but was able to reproduce this observation in multiple functions of Annotator by putting breakpoints in various places. As an example this is the handler for mousing over an annotation: https://github.com/openannotation/annotator/blob/v2.0.0-alpha.3/src/ui/viewer.js#L363

If you put a breakpoint there and move up and down the stack frames, in some frames the data objects are retrievable and in some they are not. I don't see any pattern to it though.

I thought this could be because of the way Webpack compiled the code, but this isn't related because I had the same problem when I wrote the code as a script tag using globals.

So how does this make sense? Why would jQuery data objects associated to elements be visible from certain functions but not from others?

@tilgovi
Copy link
Member

tilgovi commented Nov 26, 2019

Could there be multiple versions of jQuery in use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants