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.

Ref gh-5582
This commit is contained in:
Michał Gołębiowski-Owczarek 2024-11-18 18:28:33 +01:00
parent 041f6e347b
commit 0aedc9d59f
No known key found for this signature in database
2 changed files with 27 additions and 19 deletions

View File

@ -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;
}

View File

@ -1759,19 +1759,33 @@ 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" );
assert.equal( style.MozFakeProperty, "old value", "Fake prefixed property is not cached" );
} );
} )();
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" );
assert.equal( style.MozFakeProperty, "old value", "Fake prefixed property is not cached" );
} );
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 ) {