![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@bramus/style-observer
Advanced tools
[![@bramus/style-observer Logo](https://github.com/bramus/style-observer/raw/main/style-observer.jpg?raw=true)](https://brm.us/style-observer)
@bramus/style-observer
– MutationObserver for CSSWhile MutationObserver
can track DOM changes, it cannot be used to track style changes. This library plugs that gap and allows you to set up an observer that notifies you when the computed value of a tracked CSS property has changed.
The main use case for this library is to track changes to CSS Custom Properties (aka CSS Variables) but it can be used for other properties as well.
npm install @bramus/style-observer
import StyleObserver, { NotificationMode, ReturnFormat } from '@bramus/style-observer';
const styleObserver = new StyleObserver(
/* The StyleObserver Callback. Gets called whenever one of the observed properties changes */
(values) => {
console.log(values['--variable1'], values['--variable2'], values['display'], values['border-width']);
},
/* StyleObserver Configuration */
{
properties: ['--variable1', '--variable2', 'display', 'border-width'],
returnFormat: ReturnFormat.VALUE_ONLY,
notificationMode: NotificationMode.ALL,
}
);
styleObserver.observe(document.body); // Start observing changes to `document.body`
// …
styleObserver.unobserve(document.body); // Stop observing
notificationMode
(NotificationMode
, default: CHANGED_ONLY
): Determines whether to pass all properties (ALL
) or only the changed ones (CHANGED_ONLY
) into the callbackReturnFormat
(ReturnFormat
, default: OBJECT
): Determines the format of the data passed to the callback. Below are the options:
VALUE_ONLY
: The callback receives an object with property names as keys and their current values:
{
"--my-variable": "1.0",
"display": "block"
}
OBJECT
: The callback receives an object with property names as keys and detailed information as values:
{
"--my-variable":{
"value": "1.0",
"previousValue": "0.0",
"changed": true
}
}
Try out a demo on CodePen: https://codepen.io/bramus/pen/WNqKqxj
One single StyleObserver
instance can be used to observer mutliple elements.
const observer = new StyleObserver(…);
observer.observe(document.getElementById('mainbutton'));
observer.observe(document.getElementById('otherbutton'));
To unobserve a single element, pass a reference to it in StyleObserver
’s unobserve()
.
observer.unobserve(document.getElementById('mainbutton'));
When passing no argument in unobserve()
, the observer will unobserve all observed elements.
Below is a list of commands you will probably find useful.
npm run demo
Runs the project in development/watch mode, starts HTTP server and navigates to http://localhost:8080/demo
npm start
Runs the project in development/watch mode. Your project will be rebuilt upon changes.
npm run build
Bundles the package to the dist
folder.
The requirement for this library to work is support for CSS Transitions.
However, to also support properties that animate discretely – such as Custom Properties but also properties like display
– the browser must support transition-behavior: allow-discrete
.
In practice, this translates to the following list of browsers:
Note: All browser versions listed above have bugs when transitioning Custom Properties. As it stands right now, the only cross-browser way to observe Custom Properties with @bramus/style-observer
is to register the property with a syntax of "<custom-ident>"
, which might not be a good fit for your use-case. See https://brm.us/style-observer#custom-props for a detailed write-up.
This library doesn’t use requestAnimationFrame
but responds to transition events. Therefore it doesn’t put a recurring and constant strain on the main thread.
The original css-variable-observer
library that coined this approach only works with custom properties and numeric values. This library can work with any property having any value.
The properties that are being tracked are set to a very short transition time. If you relied on transitions for those properties, that is now no longer possible.
You can work around this by putting a value into a custom property that you track and then use that custom property in a regular property. The regular property can have any transition you want.
Also note that changing the value transition
property yourself will make this library no longer work.
This library builds upon the css-variable-observer
project by Artem Godin. The suggestion to leverage transition-behavior: allow-discrete
was done by Jake Archibald in w3c/csswg-drafts#8982.
FAQs
[![@bramus/style-observer Logo](https://github.com/bramus/style-observer/raw/main/style-observer.jpg?raw=true)](https://brm.us/style-observer)
The npm package @bramus/style-observer receives a total of 0 weekly downloads. As such, @bramus/style-observer popularity was classified as not popular.
We found that @bramus/style-observer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.