Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13760 closed bug (fixed)

getComputedStyle no longer works in node with jsdom

Reported by: m_gol Owned by:
Priority: high Milestone: None
Component: build Version: 2.0.0-beta3
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by m_gol)

I've noticed in this pull request:
a change to the parameter passed to the main enclosing IIFE, i.e. window was changed to this. The problem is, there are lots of places in jQuery where we assume window is actually window so it breaks a lot. One example is in css.js:

// NOTE: we've included the "window" in window.getComputedStyle
// because jsdom on node.js will break without it.
function getStyles( elem ) {
	return window.getComputedStyle( elem, null );

So we have a few bytes (window.) that actually fix nothing. Another example is window.addEventListener etc.

Change History (7)

comment:1 Changed 10 years ago by m_gol

I meant "a few bytes that fix nothing", not "save".

comment:2 Changed 10 years ago by Rick Waldron

What a nightmare. There are way too many places where we need window to be _window_

Last edited 10 years ago by Rick Waldron (previous) (diff)

comment:3 Changed 10 years ago by m_gol

Dave suggested we could just pass window instead of this and thus attach jQuery to window. jQuery is exported for node separately, anyway, so it shouldn't break.

If we need the global object inside, too, though, I see no other option than

(function ( global, window ) {
    /* code */
})( this, window );

comment:4 Changed 10 years ago by Timmy Willison

Component: unfiledbuild
Priority: undecidedhigh
Status: newopen

If I understand this correctly, jQuery won't work without jsdom and its window export, which means using node's global object isn't sufficient on its own. So, just passing window and continuing to assign to module.exports in the outro is probably the best option.

comment:5 Changed 10 years ago by m_gol

Description: modified (diff)

comment:6 Changed 10 years ago by m_gol

It's actually not src/outro, it's in src/exports.

Pull request: https://github.com/jquery/jquery/pull/1238

comment:7 Changed 10 years ago by Michał Gołębiowski

Resolution: fixed
Status: openclosed

Fixes #13760. Pass window, not this to the main IIFE. Closes gh-1238

Changeset: e80117adb49eff8f82140b01d755bdeefe7eb089

Note: See TracTickets for help on using tickets.