Registry / web-framework / babel-plugin-react-inline-svg-unique-id

babel-plugin-react-inline-svg-unique-id

JSON →
library1.5.0jsnpmunverified

A Babel plugin (v1.5.0) that transforms inline React SVG components at build time to replace hardcoded definition IDs with runtime-generated unique IDs, preventing ID collisions when the same SVG is used multiple times on a page. Requires the companion runtime package @inline-svg-unique-id/react. Stable, updated sporadically, maintained by a single contributor. Key differentiator: SSR-friendly with a context provider for custom ID prefixes, unlike alternatives that rely on random hashes without SSR support.

npm install babel-plugin-react-inline-svg-unique-id
INSTALL
IMPORT
SIG · BABEL-PLUGIN-REACT
B
babel-plugin-react-inline-svg-unique-id
web-frameworkjavascriptv1.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = require('babel-plugin-react-inline-svg-unique-id')
import babelPluginReactInlineSvgUniqueId from 'babel-plugin-react-inline-svg-unique-id'
CommonJS only; no default ESM export. Use require in Babel config.
useUniqueInlineId
import { useUniqueInlineId } from '@inline-svg-unique-id/react'
import useUniqueInlineId from '@inline-svg-unique-id/react'
Named export from the runtime package.
Provider
import { Provider } from '@inline-svg-unique-id/react'
import { UniqueIdGeneratorProvider } from '@inline-svg-unique-id/react'
Named export; also available as UniqueIdGeneratorProvider alias for clarity.

Shows setup with Babel config, Provider wrapper, and hook usage to generate unique SVG definition IDs.

// Install: npm install babel-plugin-react-inline-svg-unique-id @inline-svg-unique-id/react // .babelrc { "plugins": ["react-inline-svg-unique-id"] } // App.jsx import { Provider as UniqueIdGeneratorProvider } from '@inline-svg-unique-id/react'; const YourApp = () => ( <UniqueIdGeneratorProvider> <Icon /> <Icon /> </UniqueIdGeneratorProvider> ); // Icon.jsx import { useUniqueInlineId } from '@inline-svg-unique-id/react'; const Icon = () => { const gradientId = useUniqueInlineId(); return ( <svg> <defs> <linearGradient id={gradientId}> <stop offset="0%" stopColor="red" /> </linearGradient> </defs> <ellipse fill={`url(#${gradientId})`} /> </svg> ); };
Debug
Known issues
deprecatedThe plugin is not actively maintained; last update was in 2021.
fix
Consider alternatives if you need ongoing support.
affects: <=1.5.0
gotchaThe runtime package @inline-svg-unique-id/react is required and must be installed separately.
fix
Run: npm install @inline-svg-unique-id/react
affects: >=1.0.0
gotchaProvider idPrefix prop is evaluated only once; changing it on rerenders has no effect.
fix
If you need dynamic prefixes, create a new Provider instance.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module '@inline-svg-unique-id/react'
The runtime dependency is not installed.
fix
npm install @inline-svg-unique-id/react
The id 'grad1' is already defined, skipping definition
Missing Provider wrapper causing ID collision warning from browser.
fix
Wrap your app with <Provider> from '@inline-svg-unique-id/react'.
Attempted import error: 'useUniqueInlineId' is not exported from '@inline-svg-unique-id/react'
Using incorrect import syntax (default import instead of named).
fix
Use import { useUniqueInlineId } from '@inline-svg-unique-id/react'
Upgrade
Version history
1.5.0latest on npm
Audit
Dependencies
@inline-svg-unique-id/reactrequiredRuntime dependency provides useUniqueInlineId hook and Provider for SSR
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
babel-plugin-react-inline-svg-unique-id — npm install babel-plugin-react-inline-svg-unique-id · libregistry