diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2024-11-26 00:23:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-26 00:23:19 +0100 |
commit | 640d5825df5ff223560c5690f1a268681c32f9fa (patch) | |
tree | 8122dd698b06a171a482e3bbab2bf07de39975ff | |
parent | e4b5e6227717039a9c695b12e40d3f73ffec31b0 (diff) | |
download | jquery-640d5825df5ff223560c5690f1a268681c32f9fa.tar.gz jquery-640d5825df5ff223560c5690f1a268681c32f9fa.zip |
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 gh-5583
Ref gh-5582
-rw-r--r-- | src/css/finalPropName.js | 10 | ||||
-rw-r--r-- | test/unit/css.js | 34 |
2 files changed, 26 insertions, 18 deletions
diff --git a/src/css/finalPropName.js b/src/css/finalPropName.js index b11e92394..f040e6976 100644 --- a/src/css/finalPropName.js +++ b/src/css/finalPropName.js @@ -1,8 +1,7 @@ import { document } from "../var/document.js"; var cssPrefixes = [ "Webkit", "Moz", "ms" ], - emptyStyle = document.createElement( "div" ).style, - vendorProps = {}; + emptyStyle = document.createElement( "div" ).style; // Return a vendor-prefixed property or undefined function vendorPropName( name ) { @@ -21,13 +20,8 @@ function vendorPropName( name ) { // Return a potentially-mapped vendor prefixed property export function finalPropName( name ) { - var final = vendorProps[ name ]; - - if ( final ) { - return final; - } if ( name in emptyStyle ) { return name; } - return vendorProps[ name ] = vendorPropName( name ) || name; + return vendorPropName( name ) || name; } diff --git a/test/unit/css.js b/test/unit/css.js index d872e52bb..e232f5db0 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1705,7 +1705,7 @@ QUnit.test( "Do not throw on frame elements from css method (trac-15098)", funct ( function() { var vendorPrefixes = [ "Webkit", "Moz", "ms" ]; - QUnit.test( "Don't default to a cached previously used wrong prefixed name (gh-2015)", function( assert ) { + QUnit.test( "Don't default to a previously used wrong prefixed name (gh-2015)", function( assert ) { // Note: this test needs a property we know is only supported in a prefixed version // 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 assert.equal( elemStyle.undefined, undefined, "Nothing writes to node.style.undefined" ); } ); - QUnit.test( "Don't detect fake set properties on a node when caching the prefixed version", function( assert ) { - assert.expect( 1 ); +} )(); - var elem = jQuery( "<div></div>" ), - style = elem[ 0 ].style; - style.MozFakeProperty = "old value"; - elem.css( "fakeProperty", "new value" ); +QUnit.test( "Don't update existing unsupported prefixed properties", function( assert ) { + assert.expect( 1 ); - assert.equal( style.MozFakeProperty, "old value", "Fake prefixed property is not cached" ); - } ); + var elem = jQuery( "<div></div>" ), + style = elem[ 0 ].style; + style.MozFakeProperty = "old value"; + elem.css( "fakeProperty", "new value" ); -} )(); + assert.equal( style.MozFakeProperty, "old value", "Fake prefixed property is not set" ); +} ); + +QUnit.test( "Don't set fake prefixed properties when a regular one is missing", function( assert ) { + assert.expect( 5 ); + + var elem = jQuery( "<div></div>" ), + style = elem[ 0 ].style; + elem.css( "fakeProperty", "fake value" ); + + assert.strictEqual( style.fakeProperty, "fake value", "Fake unprefixed property is set" ); + assert.strictEqual( style.webkitFakeProperty, undefined, "Fake prefixed property is not set (webkit)" ); + assert.strictEqual( style.WebkitFakeProperty, undefined, "Fake prefixed property is not set (Webkit)" ); + assert.strictEqual( style.MozFakeProperty, undefined, "Fake prefixed property is not set (Moz)" ); + assert.strictEqual( style.msFakeProperty, undefined, "Fake prefixed property is not set (ms)" ); +} ); // IE doesn't support CSS variables. QUnit.testUnlessIE( "css(--customProperty)", function( assert ) { |