react-single-instance 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/index.cjs +86 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Itay Merchav
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# react-single-instance
|
|
2
|
+
|
|
3
|
+
  
|
|
4
|
+
|
|
5
|
+
Render something at most once for a given `id`, app-wide - a component, a hook, and a HOC, all sharing one registry. Useful for a modal root, a toast host, or any other element that must exist exactly once even if it gets mounted from more than one place by mistake.
|
|
6
|
+
|
|
7
|
+
Started as a small helper inside [faintlines](https://github.com/itaym/faintlines); this is the standalone, tested, rewritten version.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i react-single-instance
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { initSingleInstance, SingleInstance, useSingleInstance, withSingleInstance } from 'react-single-instance';
|
|
15
|
+
|
|
16
|
+
// once, at app startup, before anything below renders
|
|
17
|
+
initSingleInstance();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## `<SingleInstance>`
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
<SingleInstance id="modal-root">
|
|
24
|
+
<ModalHost />
|
|
25
|
+
</SingleInstance>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
If a second `<SingleInstance id="modal-root">` mounts anywhere else in the tree, it renders nothing.
|
|
29
|
+
|
|
30
|
+
## `useSingleInstance`
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
function ModalHost() {
|
|
34
|
+
const granted = useSingleInstance('modal-root');
|
|
35
|
+
return granted ? <div className="modal-host" /> : null;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## `withSingleInstance`
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
const GuardedModalHost = withSingleInstance(ModalHost, 'modal-root');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Why this needs `initSingleInstance()`
|
|
46
|
+
|
|
47
|
+
`React.StrictMode` invokes a function component's render body twice, back to back, in development only. There's no purity-safe way, from inside render, to tell "this is my own StrictMode replay" apart from "this is a genuinely different caller" - so the registry allows exactly two claims per id before rejecting the rest, which absorbs StrictMode's double-invoke without ever risking a real mount silently rendering nothing.
|
|
48
|
+
|
|
49
|
+
`initSingleInstance()` resets the registry. Call it once, synchronously, before your app renders anything that uses an id you care about - a hot reload, a new test, or a route remount that should be allowed to claim an id again all need this. Skipping it doesn't break anything by itself, but you'll get a console warning the first time an id is claimed, since un-reset ids never free up.
|
|
50
|
+
|
|
51
|
+
**Known limitation:** two genuinely different call sites that both mount with the same `id` in the same commit, *outside* of StrictMode, will both be granted - the two-slot slack that makes StrictMode safe is indistinguishable, from inside render, from two real callers. Run under StrictMode (React's development default) and a real duplicate's own two extra invocations get caught immediately; without it, a duplicate that stays mounted is still caught the moment a third claimant shows up, or after the next `initSingleInstance()` cycle.
|
|
52
|
+
|
|
53
|
+
## Playground
|
|
54
|
+
|
|
55
|
+
A live demo of all three APIs, including the re-render and reset behavior:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm run playground
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Development
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm install
|
|
65
|
+
npm run build # tsup: ESM + CJS + d.ts
|
|
66
|
+
npm test # Vitest (happy-dom)
|
|
67
|
+
npm run test:coverage
|
|
68
|
+
npm run playground # http://localhost:4174
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Have a good productive day :)
|
|
72
|
+
|
|
73
|
+
If you like this package please consider donation <a href="https://paypal.me/ItayMerchav?locale.x=en_US" target="_blank">Click Here</a>
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT © 2026 Itay Merchav
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
SingleInstance: () => SingleInstance,
|
|
24
|
+
default: () => SingleInstance_default,
|
|
25
|
+
initSingleInstance: () => initSingleInstance,
|
|
26
|
+
useSingleInstance: () => useSingleInstance,
|
|
27
|
+
withSingleInstance: () => withSingleInstance
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
|
|
31
|
+
// src/useSingleInstance.ts
|
|
32
|
+
var import_react = require("react");
|
|
33
|
+
|
|
34
|
+
// src/registry.ts
|
|
35
|
+
var STRICT_MODE_SLACK = 2;
|
|
36
|
+
var counts = /* @__PURE__ */ new Map();
|
|
37
|
+
var initialized = false;
|
|
38
|
+
function initSingleInstance() {
|
|
39
|
+
initialized = true;
|
|
40
|
+
counts.clear();
|
|
41
|
+
}
|
|
42
|
+
function claimSingleInstance(id) {
|
|
43
|
+
var _a;
|
|
44
|
+
if (!initialized && process.env.NODE_ENV !== "production") {
|
|
45
|
+
console.warn(
|
|
46
|
+
`[react-single-instance] "${id}" rendered before initSingleInstance() ran. Call initSingleInstance() once at app startup - otherwise ids never reset between test runs, hot reloads, or route remounts.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const count = (_a = counts.get(id)) != null ? _a : 0;
|
|
50
|
+
if (count >= STRICT_MODE_SLACK) return false;
|
|
51
|
+
counts.set(id, count + 1);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/useSingleInstance.ts
|
|
56
|
+
function useSingleInstance(id) {
|
|
57
|
+
const settled = (0, import_react.useRef)(void 0);
|
|
58
|
+
if (settled.current === void 0) {
|
|
59
|
+
settled.current = claimSingleInstance(id);
|
|
60
|
+
}
|
|
61
|
+
return settled.current;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/SingleInstance.tsx
|
|
65
|
+
function SingleInstance({ id, children }) {
|
|
66
|
+
return useSingleInstance(id) ? children : null;
|
|
67
|
+
}
|
|
68
|
+
var SingleInstance_default = SingleInstance;
|
|
69
|
+
|
|
70
|
+
// src/withSingleInstance.tsx
|
|
71
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
72
|
+
function withSingleInstance(Component, id) {
|
|
73
|
+
function WithSingleInstance(props) {
|
|
74
|
+
return useSingleInstance(id) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props }) : null;
|
|
75
|
+
}
|
|
76
|
+
WithSingleInstance.displayName = `withSingleInstance(${Component.displayName || Component.name || "Component"})`;
|
|
77
|
+
return WithSingleInstance;
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
SingleInstance,
|
|
82
|
+
initSingleInstance,
|
|
83
|
+
useSingleInstance,
|
|
84
|
+
withSingleInstance
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/useSingleInstance.ts","../src/registry.ts","../src/SingleInstance.tsx","../src/withSingleInstance.tsx"],"sourcesContent":["export { SingleInstance, default } from './SingleInstance';\nexport type { SingleInstanceProps } from './SingleInstance';\nexport { useSingleInstance } from './useSingleInstance';\nexport { withSingleInstance } from './withSingleInstance';\nexport { initSingleInstance } from './registry';\n","import { useRef } from 'react';\nimport { claimSingleInstance } from './registry';\n\n// Memoized so a settled instance never re-consults the registry on later re-renders (see README).\nexport function useSingleInstance(id: string): boolean {\n const settled = useRef<boolean | undefined>(undefined);\n if (settled.current === undefined) {\n settled.current = claimSingleInstance(id);\n }\n return settled.current;\n}\n","// React.StrictMode double-invokes render in dev; both calls must succeed since we can't tell which gets committed (see README).\nconst STRICT_MODE_SLACK = 2;\n\nconst counts = new Map<string, number>();\nlet initialized = false;\n\nexport function initSingleInstance(): void {\n initialized = true;\n counts.clear();\n}\n\n/** @internal exposed for tests only */\nexport function __resetSingleInstanceForTests(): void {\n counts.clear();\n initialized = false;\n}\n\nexport function claimSingleInstance(id: string): boolean {\n if (!initialized && process.env.NODE_ENV !== 'production') {\n console.warn(\n `[react-single-instance] \"${id}\" rendered before initSingleInstance() ran. ` +\n 'Call initSingleInstance() once at app startup - otherwise ids never reset ' +\n 'between test runs, hot reloads, or route remounts.',\n );\n }\n\n const count = counts.get(id) ?? 0;\n if (count >= STRICT_MODE_SLACK) return false;\n\n counts.set(id, count + 1);\n return true;\n}\n","import type { ReactNode } from 'react';\nimport { useSingleInstance } from './useSingleInstance';\n\nexport interface SingleInstanceProps {\n id: string;\n children: ReactNode;\n}\n\nexport function SingleInstance({ id, children }: SingleInstanceProps): ReactNode {\n return useSingleInstance(id) ? children : null;\n}\n\nexport default SingleInstance;\n","import type { ComponentType } from 'react';\nimport { useSingleInstance } from './useSingleInstance';\n\nexport function withSingleInstance<P extends object>(Component: ComponentType<P>, id: string): ComponentType<P> {\n function WithSingleInstance(props: P) {\n return useSingleInstance(id) ? <Component {...props} /> : null;\n }\n\n WithSingleInstance.displayName = `withSingleInstance(${Component.displayName || Component.name || 'Component'})`;\n\n return WithSingleInstance;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAuB;;;ACCvB,IAAM,oBAAoB;AAE1B,IAAM,SAAS,oBAAI,IAAoB;AACvC,IAAI,cAAc;AAEX,SAAS,qBAA2B;AACzC,gBAAc;AACd,SAAO,MAAM;AACf;AAQO,SAAS,oBAAoB,IAAqB;AAjBzD;AAkBE,MAAI,CAAC,eAAe,QAAQ,IAAI,aAAa,cAAc;AACzD,YAAQ;AAAA,MACN,4BAA4B,EAAE;AAAA,IAGhC;AAAA,EACF;AAEA,QAAM,SAAQ,YAAO,IAAI,EAAE,MAAb,YAAkB;AAChC,MAAI,SAAS,kBAAmB,QAAO;AAEvC,SAAO,IAAI,IAAI,QAAQ,CAAC;AACxB,SAAO;AACT;;;AD3BO,SAAS,kBAAkB,IAAqB;AACrD,QAAM,cAAU,qBAA4B,MAAS;AACrD,MAAI,QAAQ,YAAY,QAAW;AACjC,YAAQ,UAAU,oBAAoB,EAAE;AAAA,EAC1C;AACA,SAAO,QAAQ;AACjB;;;AEFO,SAAS,eAAe,EAAE,IAAI,SAAS,GAAmC;AAC/E,SAAO,kBAAkB,EAAE,IAAI,WAAW;AAC5C;AAEA,IAAO,yBAAQ;;;ACPoB;AAF5B,SAAS,mBAAqC,WAA6B,IAA8B;AAC9G,WAAS,mBAAmB,OAAU;AACpC,WAAO,kBAAkB,EAAE,IAAI,4CAAC,aAAW,GAAG,OAAO,IAAK;AAAA,EAC5D;AAEA,qBAAmB,cAAc,sBAAsB,UAAU,eAAe,UAAU,QAAQ,WAAW;AAE7G,SAAO;AACT;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode, ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
interface SingleInstanceProps {
|
|
4
|
+
id: string;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
declare function SingleInstance({ id, children }: SingleInstanceProps): ReactNode;
|
|
8
|
+
|
|
9
|
+
declare function useSingleInstance(id: string): boolean;
|
|
10
|
+
|
|
11
|
+
declare function withSingleInstance<P extends object>(Component: ComponentType<P>, id: string): ComponentType<P>;
|
|
12
|
+
|
|
13
|
+
declare function initSingleInstance(): void;
|
|
14
|
+
|
|
15
|
+
export { SingleInstance, type SingleInstanceProps, SingleInstance as default, initSingleInstance, useSingleInstance, withSingleInstance };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode, ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
interface SingleInstanceProps {
|
|
4
|
+
id: string;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
declare function SingleInstance({ id, children }: SingleInstanceProps): ReactNode;
|
|
8
|
+
|
|
9
|
+
declare function useSingleInstance(id: string): boolean;
|
|
10
|
+
|
|
11
|
+
declare function withSingleInstance<P extends object>(Component: ComponentType<P>, id: string): ComponentType<P>;
|
|
12
|
+
|
|
13
|
+
declare function initSingleInstance(): void;
|
|
14
|
+
|
|
15
|
+
export { SingleInstance, type SingleInstanceProps, SingleInstance as default, initSingleInstance, useSingleInstance, withSingleInstance };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/useSingleInstance.ts
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
|
|
4
|
+
// src/registry.ts
|
|
5
|
+
var STRICT_MODE_SLACK = 2;
|
|
6
|
+
var counts = /* @__PURE__ */ new Map();
|
|
7
|
+
var initialized = false;
|
|
8
|
+
function initSingleInstance() {
|
|
9
|
+
initialized = true;
|
|
10
|
+
counts.clear();
|
|
11
|
+
}
|
|
12
|
+
function claimSingleInstance(id) {
|
|
13
|
+
var _a;
|
|
14
|
+
if (!initialized && process.env.NODE_ENV !== "production") {
|
|
15
|
+
console.warn(
|
|
16
|
+
`[react-single-instance] "${id}" rendered before initSingleInstance() ran. Call initSingleInstance() once at app startup - otherwise ids never reset between test runs, hot reloads, or route remounts.`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
const count = (_a = counts.get(id)) != null ? _a : 0;
|
|
20
|
+
if (count >= STRICT_MODE_SLACK) return false;
|
|
21
|
+
counts.set(id, count + 1);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/useSingleInstance.ts
|
|
26
|
+
function useSingleInstance(id) {
|
|
27
|
+
const settled = useRef(void 0);
|
|
28
|
+
if (settled.current === void 0) {
|
|
29
|
+
settled.current = claimSingleInstance(id);
|
|
30
|
+
}
|
|
31
|
+
return settled.current;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/SingleInstance.tsx
|
|
35
|
+
function SingleInstance({ id, children }) {
|
|
36
|
+
return useSingleInstance(id) ? children : null;
|
|
37
|
+
}
|
|
38
|
+
var SingleInstance_default = SingleInstance;
|
|
39
|
+
|
|
40
|
+
// src/withSingleInstance.tsx
|
|
41
|
+
import { jsx } from "react/jsx-runtime";
|
|
42
|
+
function withSingleInstance(Component, id) {
|
|
43
|
+
function WithSingleInstance(props) {
|
|
44
|
+
return useSingleInstance(id) ? /* @__PURE__ */ jsx(Component, { ...props }) : null;
|
|
45
|
+
}
|
|
46
|
+
WithSingleInstance.displayName = `withSingleInstance(${Component.displayName || Component.name || "Component"})`;
|
|
47
|
+
return WithSingleInstance;
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
SingleInstance,
|
|
51
|
+
SingleInstance_default as default,
|
|
52
|
+
initSingleInstance,
|
|
53
|
+
useSingleInstance,
|
|
54
|
+
withSingleInstance
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useSingleInstance.ts","../src/registry.ts","../src/SingleInstance.tsx","../src/withSingleInstance.tsx"],"sourcesContent":["import { useRef } from 'react';\nimport { claimSingleInstance } from './registry';\n\n// Memoized so a settled instance never re-consults the registry on later re-renders (see README).\nexport function useSingleInstance(id: string): boolean {\n const settled = useRef<boolean | undefined>(undefined);\n if (settled.current === undefined) {\n settled.current = claimSingleInstance(id);\n }\n return settled.current;\n}\n","// React.StrictMode double-invokes render in dev; both calls must succeed since we can't tell which gets committed (see README).\nconst STRICT_MODE_SLACK = 2;\n\nconst counts = new Map<string, number>();\nlet initialized = false;\n\nexport function initSingleInstance(): void {\n initialized = true;\n counts.clear();\n}\n\n/** @internal exposed for tests only */\nexport function __resetSingleInstanceForTests(): void {\n counts.clear();\n initialized = false;\n}\n\nexport function claimSingleInstance(id: string): boolean {\n if (!initialized && process.env.NODE_ENV !== 'production') {\n console.warn(\n `[react-single-instance] \"${id}\" rendered before initSingleInstance() ran. ` +\n 'Call initSingleInstance() once at app startup - otherwise ids never reset ' +\n 'between test runs, hot reloads, or route remounts.',\n );\n }\n\n const count = counts.get(id) ?? 0;\n if (count >= STRICT_MODE_SLACK) return false;\n\n counts.set(id, count + 1);\n return true;\n}\n","import type { ReactNode } from 'react';\nimport { useSingleInstance } from './useSingleInstance';\n\nexport interface SingleInstanceProps {\n id: string;\n children: ReactNode;\n}\n\nexport function SingleInstance({ id, children }: SingleInstanceProps): ReactNode {\n return useSingleInstance(id) ? children : null;\n}\n\nexport default SingleInstance;\n","import type { ComponentType } from 'react';\nimport { useSingleInstance } from './useSingleInstance';\n\nexport function withSingleInstance<P extends object>(Component: ComponentType<P>, id: string): ComponentType<P> {\n function WithSingleInstance(props: P) {\n return useSingleInstance(id) ? <Component {...props} /> : null;\n }\n\n WithSingleInstance.displayName = `withSingleInstance(${Component.displayName || Component.name || 'Component'})`;\n\n return WithSingleInstance;\n}\n"],"mappings":";AAAA,SAAS,cAAc;;;ACCvB,IAAM,oBAAoB;AAE1B,IAAM,SAAS,oBAAI,IAAoB;AACvC,IAAI,cAAc;AAEX,SAAS,qBAA2B;AACzC,gBAAc;AACd,SAAO,MAAM;AACf;AAQO,SAAS,oBAAoB,IAAqB;AAjBzD;AAkBE,MAAI,CAAC,eAAe,QAAQ,IAAI,aAAa,cAAc;AACzD,YAAQ;AAAA,MACN,4BAA4B,EAAE;AAAA,IAGhC;AAAA,EACF;AAEA,QAAM,SAAQ,YAAO,IAAI,EAAE,MAAb,YAAkB;AAChC,MAAI,SAAS,kBAAmB,QAAO;AAEvC,SAAO,IAAI,IAAI,QAAQ,CAAC;AACxB,SAAO;AACT;;;AD3BO,SAAS,kBAAkB,IAAqB;AACrD,QAAM,UAAU,OAA4B,MAAS;AACrD,MAAI,QAAQ,YAAY,QAAW;AACjC,YAAQ,UAAU,oBAAoB,EAAE;AAAA,EAC1C;AACA,SAAO,QAAQ;AACjB;;;AEFO,SAAS,eAAe,EAAE,IAAI,SAAS,GAAmC;AAC/E,SAAO,kBAAkB,EAAE,IAAI,WAAW;AAC5C;AAEA,IAAO,yBAAQ;;;ACPoB;AAF5B,SAAS,mBAAqC,WAA6B,IAA8B;AAC9G,WAAS,mBAAmB,OAAU;AACpC,WAAO,kBAAkB,EAAE,IAAI,oBAAC,aAAW,GAAG,OAAO,IAAK;AAAA,EAC5D;AAEA,qBAAmB,cAAc,sBAAsB,UAAU,eAAe,UAAU,QAAQ,WAAW;AAE7G,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-single-instance",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Render a component at most once for a given id, app-wide - safely absorbs React.StrictMode's dev double-invoke",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup",
|
|
22
|
+
"dev": "tsup --watch",
|
|
23
|
+
"typecheck": "tsc --noEmit -p . && tsc --noEmit -p playground",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"playground": "npm --prefix playground run dev",
|
|
28
|
+
"playground:build": "npm run build && npm --prefix playground install && npm --prefix playground run build",
|
|
29
|
+
"playground:preview": "npm --prefix playground run preview",
|
|
30
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\" \"playground/src/**/*.{ts,tsx}\"",
|
|
31
|
+
"format:check": "prettier --check \"src/**/*.{ts,tsx}\" \"playground/src/**/*.{ts,tsx}\""
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"react",
|
|
35
|
+
"strict-mode",
|
|
36
|
+
"singleton",
|
|
37
|
+
"idempotent",
|
|
38
|
+
"hook",
|
|
39
|
+
"hoc",
|
|
40
|
+
"modal",
|
|
41
|
+
"guard"
|
|
42
|
+
],
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/itaym/react-single-instance.git"
|
|
46
|
+
},
|
|
47
|
+
"author": "Itay Merchav",
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/itaym/react-single-instance/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/itaym/react-single-instance#readme",
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": ">=17"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@testing-library/dom": "^10.4.0",
|
|
58
|
+
"@testing-library/jest-dom": "^6.5.0",
|
|
59
|
+
"@testing-library/react": "^16.0.1",
|
|
60
|
+
"@types/node": "^20.14.15",
|
|
61
|
+
"@types/react": "^18.3.5",
|
|
62
|
+
"@types/react-dom": "^18.3.0",
|
|
63
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
64
|
+
"happy-dom": "^20.14.0",
|
|
65
|
+
"prettier": "^3.3.3",
|
|
66
|
+
"react": "^18.3.1",
|
|
67
|
+
"react-dom": "^18.3.1",
|
|
68
|
+
"tsup": "^8.2.4",
|
|
69
|
+
"typescript": "^5.5.4",
|
|
70
|
+
"vitest": "^4.1.11"
|
|
71
|
+
}
|
|
72
|
+
}
|