Skip to content

Commit 640d582

Browse files
authored
CSS: Drop the cache in finalPropName
The `finalPropName` util caches properties detected to require a vendor prefix. This used to cache unprefixed properties as well, but it was reported that this logic broke accidentally during a refactor. Since fewer & fewer properties require a vendor prefix and caching a few basic checks likely has negligible perf benefits, opt to saving a few bytes and remove the cache. Closes jquerygh-5583 Ref jquerygh-5582
1 parent e4b5e62 commit 640d582

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/css/finalPropName.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { document } from "../var/document.js";
22

33
var cssPrefixes = [ "Webkit", "Moz", "ms" ],
4-
emptyStyle = document.createElement( "div" ).style,
5-
vendorProps = {};
4+
emptyStyle = document.createElement( "div" ).style;
65

76
// Return a vendor-prefixed property or undefined
87
function vendorPropName( name ) {
@@ -21,13 +20,8 @@ function vendorPropName( name ) {
2120

2221
// Return a potentially-mapped vendor prefixed property
2322
export function finalPropName( name ) {
24-
var final = vendorProps[ name ];
25-
26-
if ( final ) {
27-
return final;
28-
}
2923
if ( name in emptyStyle ) {
3024
return name;
3125
}
32-
return vendorProps[ name ] = vendorPropName( name ) || name;
26+
return vendorPropName( name ) || name;
3327
}

test/unit/css.js

+24-10
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ QUnit.test( "Do not throw on frame elements from css method (trac-15098)", funct
17051705
( function() {
17061706
var vendorPrefixes = [ "Webkit", "Moz", "ms" ];
17071707

1708-
QUnit.test( "Don't default to a cached previously used wrong prefixed name (gh-2015)", function( assert ) {
1708+
QUnit.test( "Don't default to a previously used wrong prefixed name (gh-2015)", function( assert ) {
17091709

17101710
// Note: this test needs a property we know is only supported in a prefixed version
17111711
// by at least one of our main supported browsers. This may get out of date so let's
@@ -1759,18 +1759,32 @@ QUnit.test( "Do not throw on frame elements from css method (trac-15098)", funct
17591759
assert.equal( elemStyle.undefined, undefined, "Nothing writes to node.style.undefined" );
17601760
} );
17611761

1762-
QUnit.test( "Don't detect fake set properties on a node when caching the prefixed version", function( assert ) {
1763-
assert.expect( 1 );
1762+
} )();
17641763

1765-
var elem = jQuery( "<div></div>" ),
1766-
style = elem[ 0 ].style;
1767-
style.MozFakeProperty = "old value";
1768-
elem.css( "fakeProperty", "new value" );
1764+
QUnit.test( "Don't update existing unsupported prefixed properties", function( assert ) {
1765+
assert.expect( 1 );
17691766

1770-
assert.equal( style.MozFakeProperty, "old value", "Fake prefixed property is not cached" );
1771-
} );
1767+
var elem = jQuery( "<div></div>" ),
1768+
style = elem[ 0 ].style;
1769+
style.MozFakeProperty = "old value";
1770+
elem.css( "fakeProperty", "new value" );
17721771

1773-
} )();
1772+
assert.equal( style.MozFakeProperty, "old value", "Fake prefixed property is not set" );
1773+
} );
1774+
1775+
QUnit.test( "Don't set fake prefixed properties when a regular one is missing", function( assert ) {
1776+
assert.expect( 5 );
1777+
1778+
var elem = jQuery( "<div></div>" ),
1779+
style = elem[ 0 ].style;
1780+
elem.css( "fakeProperty", "fake value" );
1781+
1782+
assert.strictEqual( style.fakeProperty, "fake value", "Fake unprefixed property is set" );
1783+
assert.strictEqual( style.webkitFakeProperty, undefined, "Fake prefixed property is not set (webkit)" );
1784+
assert.strictEqual( style.WebkitFakeProperty, undefined, "Fake prefixed property is not set (Webkit)" );
1785+
assert.strictEqual( style.MozFakeProperty, undefined, "Fake prefixed property is not set (Moz)" );
1786+
assert.strictEqual( style.msFakeProperty, undefined, "Fake prefixed property is not set (ms)" );
1787+
} );
17741788

17751789
// IE doesn't support CSS variables.
17761790
QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {

0 commit comments

Comments
 (0)