
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
background-only
Advanced tools
This is a marker package to indicate that a module can only be used in the Background Thread.
This is a marker package to indicate that a module can only be used in the Background thread.
Say we have a Logger
module that has side effects calling into Native Modules or other APIs that are only available in the "Background" environment:
// Logger.js
import "background-only";
export function log(msg) {
// Notice how we are calling into NativeModules here.
NativeModules.hybridMonitor.reportJSError(...);
}
By adding import "background-only"
to poison this module, we are now declaring that this module is only safe to be bundled in a "Background" environment, protecting this module from being accidentally bundled into a "Main thread" environment by throwing an error at runtime.
For example, if we use log
in a desirable position from a React component, such as in useEffect
or an event handler, the log
will work as expected:
// App.jsx
import { log } from "./Logger";
function App() {
useEffect() {
log();
}
return <view />
}
However, if we use log
in a undesirable position from a React component, such as in the body of the rendering function, it will throw an error at runtime time:
// App.jsx
import { log } from "./Logger";
function App() {
// throw!
log();
return <view />
}
This is inspired by the server-only
package of React.
FAQs
This is a marker package to indicate that a module can only be used in the Background Thread.
The npm package background-only receives a total of 3,616 weekly downloads. As such, background-only popularity was classified as popular.
We found that background-only 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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.