![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@fluentui/babel-preset-global-context
Advanced tools
Babel preset that transforms createContext calls to use global context shims
Babel Preset Global Context for Fluent UI React
Babel preset that transforms createContext calls to use global context shims
yarn add --dev @fluentui/babel-preset-global-context
# or
npm install --dev @fluentui/babel-preset-global-context
This preset is mainly inteded for application developers to target specific libraries that use React context and suffer from the context duplication problem. React contexts are not real singletons and are scoped by module level. This can cause problems when the context is duplicated in node_modules.
This is a known issue that is by design according to facebook/react#13346 that is illustrated in the below example.
// my-context-package
import * as React from 'react';
export const MyContext = React.createContext({ foo: 'foo' });
// provider.ts
// node_modules/my-context-package/lib/index.js
import { MyContext } from 'my-context-package';
function Provider({ children }) {
const ctx = { foo: 'bar' };
// 1. Instantiate context with value foo='bar'
return <MyContext.Provider value={ctx}>{children}</MyContext.Provider>;
}
// consumer.ts
// node_modules/nested-dep/node_modules/my-context-package/lib/index.js
import * as React from 'react';
import { MyContext } from 'my-context-package';
function Consumer() {
// 2. Consume the 'same' context from different module
const ctx = React.useContext(MyContext);
// 3. ⚠️ Actual value would be the default 'foo'
return <div>{ctx.foo}</div>;
}
⚠️ The recommended solution to the above problem is to make sure that the affected dependency only exists once in node_modules. You can do this by upgrading your dependencies or using resolutions.
This library should only be used as a workaround in the cases where it might not be feasible to deduplicate node_modules
.
Install the shims for createContext
that will this Babel preset will use to replace original React.createContext
calls.
yarn add @fluentui/global-context
# or
npm install @fluentui/global-context
We recommend using this preset with Webpack and babel-loader while scoping the transforms to the affected packages.
// weboack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(ts|js|tsx|jsx)$/,
use: {
loader: 'babel-loader',
options: {
presets: [['@fluentui/babel-preset-global-context']],
},
},
// Targets all @fluentui scoped packages and replaces `createContext` calls with global context
// Can be setup for other packages
// /node_modules\/(<packageName>|<pacakgeName>)\/*/
include: [/node_modules\/@fluentui\/*/],
},
{
test: /\.(ts|tsx)$/i,
use: ['ts-loader'],
exclude: ['/node_modules/'],
},
],
},
};
FAQs
Babel preset that transforms createContext calls to use global context shims
The npm package @fluentui/babel-preset-global-context receives a total of 0 weekly downloads. As such, @fluentui/babel-preset-global-context popularity was classified as not popular.
We found that @fluentui/babel-preset-global-context 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.