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

Since v2.2.0: Cannot read property 'opener' of null when $.parseHTML and then get css style #2866

Closed
todorpr opened this Issue Jan 25, 2016 · 5 comments

Comments

Projects
None yet
4 participants
@todorpr
Contributor

todorpr commented Jan 25, 2016

I just upgraded to jQuery v2.2.0 and this problem appeared.

I could reproduce it in the following case:

  • parse some html using $.parseHTML
var el = $.parseHTML('<span style="font-family: Cuprum,sans-serif; font-size: 14px; color: #999999;">some text</span>');
  • on the already parsed html wrap it in jQuery container:
var span = $(el[0]);
  • now try to get css style on the jQuery element:
var style = span.css("font-size");
console.log(style);

Which results in:

Uncaught TypeError: Cannot read property 'opener' of null

jsBin: http://jsbin.com/ruyecuxogu/edit?html,js,console,output

@todorpr

This comment has been minimized.

Show comment
Hide comment
@todorpr

todorpr Jan 25, 2016

Contributor

I found out that the problem comes from this function
https://github.com/jquery/jquery/blob/99e8ff1baa7ae341e94bb89c3e84570c7c3ad9ea/src/css/var/getStyles.js

if change:

if (!view.opener ) {
    view = window;
}

to:

if (!view || !view.opener ) {
    view = window;
}

the error disappears and getting css style is done properly.

Contributor

todorpr commented Jan 25, 2016

I found out that the problem comes from this function
https://github.com/jquery/jquery/blob/99e8ff1baa7ae341e94bb89c3e84570c7c3ad9ea/src/css/var/getStyles.js

if change:

if (!view.opener ) {
    view = window;
}

to:

if (!view || !view.opener ) {
    view = window;
}

the error disappears and getting css style is done properly.

@timmywil timmywil added this to the 1.12.1/2.2.1 milestone Jan 25, 2016

@timmywil timmywil added the CSS label Jan 25, 2016

@markelog

This comment has been minimized.

Show comment
Hide comment
@markelog

markelog Jan 25, 2016

Member

Hm, it seems issue is relevant for the beta too

Member

markelog commented Jan 25, 2016

Hm, it seems issue is relevant for the beta too

@markelog markelog self-assigned this Jan 25, 2016

todorpr added a commit to todorpr/jquery that referenced this issue Jan 25, 2016

Make sure elem.ownerDocument.defaultView is not null
Since v2.2.0: Cannot read property 'opener' of null when $.parseHTML and then get css style #2866
jquery#2866
@gibson042

This comment has been minimized.

Show comment
Hide comment
@gibson042

gibson042 Jan 25, 2016

Member

This is caused by cfe468f, right?

document.implementation.createHTMLDocument( "" ).defaultView
// → null
Member

gibson042 commented Jan 25, 2016

This is caused by cfe468f, right?

document.implementation.createHTMLDocument( "" ).defaultView
// → null
@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil Jan 25, 2016

Member

@gibson042 Must be, but are you implying that createHTMLDocument isn't worth it? Current solution is to default to the current window, which might even be alright when building append-able elements for iframes.

Member

timmywil commented Jan 25, 2016

@gibson042 Must be, but are you implying that createHTMLDocument isn't worth it? Current solution is to default to the current window, which might even be alright when building append-able elements for iframes.

@gibson042

This comment has been minimized.

Show comment
Hide comment
@gibson042

gibson042 Jan 25, 2016

Member

I'm not implying that, just trying to establish the blast radius. The fix proposed in #2867 seems fine.

Member

gibson042 commented Jan 25, 2016

I'm not implying that, just trying to establish the blast radius. The fix proposed in #2867 seems fine.

@timmywil timmywil closed this in 35c3148 Jan 27, 2016

northerner added a commit to Yoomee/pig that referenced this issue Apr 13, 2016

update jquery rails to fix regression
this issue was breaking some feature tests
jquery/jquery#2866

@lock lock bot locked as resolved and limited conversation to collaborators Jun 18, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.