GithubHelp home page GithubHelp logo

Comments (1)

jhildenbiddle avatar jhildenbiddle commented on July 23, 2024

The HTML <style> element does not support the disabled attribute. IE supports it, but no other browser does. This is why the ponyfill ignores the disabled attribute on <style> elements.

https://stackoverflow.com/questions/5757231/disabled-true-can-be-set-dynamically-on-style-why-not-statically

The ponyfill does support the disabled property on the HTMLLinkElement.sheet and HTMLStyleElement.sheet objects. Alternatively, you can also just remove the <link> or <style> element from the DOM.

Parsed cssTree and pasreVars should be cached and not re-parsed

See the __cssVars property attached to any <link> or <style> element with a data-cssvars="src" attribute. You'll find the the cssTree object and the original CSS text stored there. The CSS text is used for comparison because any change to it will require generating new CSS output (i.e., the ponyfill has to be aware of more than just variable changes). Variables are cached elsewhere and do not need to be stored on a per-node basis:

const variableStore = {
// Parsed DOM values (from <link> and <style> nodes)
dom : {},
// Temporary storage for each job
job : {},
// Persisted options.variables values
user: {}
};

You are right about the unnecessary processing here though:

const nodeCSS = cssArray[i];
// Node data cache
node.__cssVars = node.__cssVars || {};
node.__cssVars.text = nodeCSS;
// Only process CSS contains a custom property
// declarations or function
if (regex.cssVars.test(nodeCSS)) {

Instead of blindly assigning nodeCSS to node.__cssVars.text, the ponyfill should be checking to see if node.__cssVars.text exists and if it matches nodeCSS to determine if the node needs to be processed.

const nodeCSS = cssArray[i];
const hasCSSCache = Boolean(node.__cssVars && node.__cssVars.text);
const hasCSSChanged = hasCSSCache && node.__cssVars.text !== nodeCSS;

// Node data cache
node.__cssVars = node.__cssVars || {};
node.__cssVars.text = nodeCSS;

// Only process CSS if it has changed or contains a
// custom property declarations or function
if ((hasCSSCache && hasCSSChanged) || regex.cssVars.test(nodeCSS)) {

I'll have to do some testing to verify that the change is is beneficial. It's been a while since I've looked at the code.

from css-vars-ponyfill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.