react-broadcast-sync 1.0.0 → 1.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/.eslintignore +5 -0
- package/.github/workflows/ci.yml +3 -3
- package/.github/workflows/release.yml +39 -0
- package/.husky/pre-commit +0 -1
- package/.nvmrc +1 -0
- package/.prettierignore +1 -0
- package/.prettierrc +5 -1
- package/CHANGELOG.md +20 -0
- package/README.md +118 -47
- package/demo/react-broadcast-sync-demo/README.md +130 -0
- package/demo/react-broadcast-sync-demo/index.html +14 -0
- package/demo/react-broadcast-sync-demo/package-lock.json +6379 -0
- package/demo/react-broadcast-sync-demo/package.json +42 -0
- package/demo/react-broadcast-sync-demo/public/assets/react-broadcast-sync-logo.png +0 -0
- package/demo/react-broadcast-sync-demo/src/App.tsx +277 -0
- package/demo/react-broadcast-sync-demo/src/components/Counter.tsx +63 -0
- package/demo/react-broadcast-sync-demo/src/components/TextSync.tsx +61 -0
- package/demo/react-broadcast-sync-demo/src/components/TodoList.tsx +186 -0
- package/demo/react-broadcast-sync-demo/src/hooks/useCounterBroadcast.ts +94 -0
- package/demo/react-broadcast-sync-demo/src/hooks/useTextBroadcast.ts +37 -0
- package/demo/react-broadcast-sync-demo/src/hooks/useTodoBroadcast.ts +249 -0
- package/demo/react-broadcast-sync-demo/src/main.tsx +11 -0
- package/demo/react-broadcast-sync-demo/src/theme.ts +62 -0
- package/demo/react-broadcast-sync-demo/tsconfig.json +26 -0
- package/demo/react-broadcast-sync-demo/tsconfig.node.json +10 -0
- package/demo/react-broadcast-sync-demo/vite.config.ts +12 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/eslint.config.js +14 -5
- package/jest.config.cjs +8 -9
- package/package.json +63 -33
- package/rollup.config.mjs +27 -21
- package/src/BroadcastProvider.tsx +6 -6
- package/src/hooks/useBroadcastChannel.ts +122 -95
- package/src/index.ts +1 -1
- package/src/tests/BroadcastProvider.test.tsx +7 -7
- package/src/tests/debug.test.ts +65 -25
- package/src/tests/messageUtils.test.ts +20 -15
- package/src/tests/useBroadcastChannel.test.tsx +48 -33
- package/src/types/types.ts +19 -23
- package/src/utils/debug.ts +1 -1
- package/src/utils/messageUtils.ts +19 -24
- package/dist/useBroadcastChannel.d.ts +0 -3
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/utils/messageUtils.ts","../src/utils/debug.ts","../src/hooks/useBroadcastChannel.ts","../src/BroadcastProvider.tsx"],"sourcesContent":[null,null,null,null],"names":["INTERNAL_PREFIX","generateRandomPart","Math","random","toString","substr","generateMessageId","source","timestamp","raw","btoa","replace","isMessageExpired","message","expirationDate","Date","now","getInternalMessageType","baseType","channelName","namespace","hash","isInternalType","type","startsWith","
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/utils/messageUtils.ts","../src/utils/debug.ts","../src/hooks/useBroadcastChannel.ts","../src/BroadcastProvider.tsx"],"sourcesContent":[null,null,null,null],"names":["INTERNAL_PREFIX","generateRandomPart","Math","random","toString","substr","generateMessageId","source","timestamp","raw","btoa","replace","isMessageExpired","message","expirationDate","Date","now","getInternalMessageType","baseType","channelName","namespace","hash","isInternalType","type","startsWith","log","level","data","process","env","REACT_APP_DEBUG_BROADCAST","prefix","toISOString","console","warn","error","debug","created","closed","sent","received","cleared","messageId","expired","duplicate","started","completed","removedCount","INTERNAL_MESSAGE_TYPES","useBroadcastChannel","options","sourceName","cleaningInterval","keepLatestMessage","registeredTypes","deduplicationTTL","cleanupDebounceMs","messages","setMessages","useState","sentMessages","setSentMessages","setError","channel","useRef","receivedMessageIds","Map","current","internalTypes","CLEAR_MESSAGE","CLEAR_ALL_MESSAGES","resolvedChannelName","useMemo","performCleanup","useCallback","prev","filter","msg","debouncedCleanup","debounce","fn","wait","result","timeoutId","lastArgs","debounced","args","clearTimeout","setTimeout","cancel","flush","Object","assign","setErrorMessage","clearMessage","id","_a","postMessage","clearAllMessages","clearSentMessage","messageType","messageContent","channelCurrent","createMessage","content","expirationDuration","undefined","e","handleMessage","event","Boolean","isValidMessage","length","includes","isValidInternalClearMessage","receivedAt","get","set","useEffect","BroadcastChannel","bc","addEventListener","removeEventListener","close","interval","setInterval","before","clearInterval","call","entries","delete","BroadcastChannelContext","createContext","ErrorBoundary","React","Component","constructor","this","state","hasError","getDerivedStateFromError","componentDidCatch","render","_jsx","props","children","BroadcastProvider","hookError","value","Provider","useBroadcastProvider","context","useContext","Error"],"mappings":"wKAAA,MAAMA,EAAkB,eAIXC,EAAqBA,IAAMC,KAAKC,SAASC,SAAS,IAAIC,OAAO,EAAG,GAMhEC,EAAoBA,CAACC,EAAgBC,KAChD,MAAMC,EAAM,GAAGR,OAAwBM,KAAUC,IACjD,OAAOE,KAAKD,GAAKE,QAAQ,MAAO,KASrBC,EAAoBC,KACxBA,EAAQC,gBAAiBD,EAAQC,eAAiBC,KAAKC,MAuBnDC,EAAyBA,CACpCC,EACAC,EACAC,EAAY,MAEZ,MAEMC,EAAOX,KADC,wBAAaQ,KADP,GAAGC,KAAeC,OAGtC,MAAO,GAAGpB,KAAmBkB,KAAYG,KAG9BC,EAAkBC,GACtBA,EAAKC,WAAW,GAAGxB,MC9CtByB,EAAMA,CAACC,EAAiBb,EAAiBc,KAC7C,GATuB,oBAAZC,UAA2BA,QAAQC,KACK,SAA1CD,QAAQC,IAAIC,0BAQD,OAEpB,MACMC,EAAS,KADG,IAAIhB,MAAOiB,wCAE7B,OAAQN,GACN,IAAK,OACHO,QAAQR,IAAIM,EAAQlB,EAASc,GAAQ,IACrC,MACF,IAAK,OACHM,QAAQC,KAAKH,EAAQlB,EAASc,GAAQ,IACtC,MACF,IAAK,QACHM,QAAQE,MAAMJ,EAAQlB,EAASc,GAAQ,MAKhCS,EACF,CACPC,QAAUlB,GAAwBM,EAAI,OA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K,EAAuBA,KAClC,MAAMC,EAAUC,EAAWrB,GAC3B,IAAKoB,EACH,MAAM,IAAIE,MAAM,gEAElB,OAAOF"}
|
package/eslint.config.js
CHANGED
|
@@ -8,8 +8,7 @@ export default [
|
|
|
8
8
|
eslint.configs.recommended,
|
|
9
9
|
...tseslint.configs.recommended,
|
|
10
10
|
{
|
|
11
|
-
files: ['src/**/*.{ts,tsx}'],
|
|
12
|
-
ignores: ['**/*', '!src/**/*.{ts,tsx}'],
|
|
11
|
+
files: ['src/**/*.{ts,tsx}', 'demo/**/*.{ts,tsx}'],
|
|
13
12
|
plugins: {
|
|
14
13
|
react: reactPlugin,
|
|
15
14
|
'react-hooks': reactHooksPlugin,
|
|
@@ -18,12 +17,22 @@ export default [
|
|
|
18
17
|
rules: {
|
|
19
18
|
'react/react-in-jsx-scope': 'off',
|
|
20
19
|
'react/prop-types': 'off',
|
|
21
|
-
'@typescript-eslint/no-unused-vars': [
|
|
20
|
+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
21
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
22
|
+
'@typescript-eslint/no-explicit-any': [
|
|
22
23
|
'warn',
|
|
23
|
-
{
|
|
24
|
+
{
|
|
25
|
+
ignoreRestArgs: true,
|
|
26
|
+
fixToUnknown: false,
|
|
27
|
+
},
|
|
24
28
|
],
|
|
25
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
26
29
|
'prettier/prettier': 'error',
|
|
27
30
|
},
|
|
28
31
|
},
|
|
32
|
+
{
|
|
33
|
+
files: ['**/*.test.{ts,tsx}', '**/*.d.ts'],
|
|
34
|
+
rules: {
|
|
35
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
29
38
|
];
|
package/jest.config.cjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'jsdom',
|
|
4
|
+
transform: {
|
|
5
|
+
'^.+\\.(ts|tsx)$': 'ts-jest',
|
|
6
|
+
},
|
|
7
|
+
testMatch: ['**/src/tests/**/*.test.(ts|tsx)'],
|
|
8
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-broadcast-sync",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A lightweight React hook and provider for syncing state across browser tabs using BroadcastChannel API.",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -18,19 +18,47 @@
|
|
|
18
18
|
"build": "rollup -c rollup.config.mjs",
|
|
19
19
|
"prepare": "npm run build && husky install",
|
|
20
20
|
"test": "jest",
|
|
21
|
-
"lint": "eslint
|
|
21
|
+
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-pattern dist",
|
|
22
22
|
"typecheck": "tsc --noEmit",
|
|
23
23
|
"format": "prettier --write .",
|
|
24
24
|
"format:check": "prettier --check .",
|
|
25
25
|
"release": "semantic-release",
|
|
26
26
|
"lint-staged": "lint-staged"
|
|
27
27
|
},
|
|
28
|
+
"release": {
|
|
29
|
+
"branches": [
|
|
30
|
+
"main"
|
|
31
|
+
],
|
|
32
|
+
"plugins": [
|
|
33
|
+
"@semantic-release/commit-analyzer",
|
|
34
|
+
"@semantic-release/release-notes-generator",
|
|
35
|
+
"@semantic-release/changelog",
|
|
36
|
+
"@semantic-release/npm",
|
|
37
|
+
"@semantic-release/github",
|
|
38
|
+
[
|
|
39
|
+
"@semantic-release/git",
|
|
40
|
+
{
|
|
41
|
+
"assets": [
|
|
42
|
+
"package.json",
|
|
43
|
+
"CHANGELOG.md"
|
|
44
|
+
],
|
|
45
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
28
53
|
"lint-staged": {
|
|
29
54
|
"*.{ts,tsx}": [
|
|
30
55
|
"eslint --fix",
|
|
31
56
|
"prettier --write"
|
|
32
57
|
]
|
|
33
58
|
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=20.11.1"
|
|
61
|
+
},
|
|
34
62
|
"keywords": [
|
|
35
63
|
"react",
|
|
36
64
|
"hooks",
|
|
@@ -68,42 +96,44 @@
|
|
|
68
96
|
"devDependencies": {
|
|
69
97
|
"@babel/core": "^7.24.0",
|
|
70
98
|
"@babel/plugin-transform-runtime": "^7.24.0",
|
|
71
|
-
"@babel/preset-react": "^7.
|
|
72
|
-
"@commitlint/cli": "^19.
|
|
73
|
-
"@commitlint/config-conventional": "^19.
|
|
99
|
+
"@babel/preset-react": "^7.23.3",
|
|
100
|
+
"@commitlint/cli": "^19.0.3",
|
|
101
|
+
"@commitlint/config-conventional": "^19.0.3",
|
|
74
102
|
"@rollup/plugin-babel": "^6.0.4",
|
|
75
|
-
"@rollup/plugin-commonjs": "^
|
|
76
|
-
"@rollup/plugin-node-resolve": "^
|
|
103
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
104
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
77
105
|
"@rollup/plugin-terser": "^0.4.4",
|
|
78
|
-
"@rollup/plugin-typescript": "^
|
|
106
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
79
107
|
"@semantic-release/changelog": "^6.0.3",
|
|
80
108
|
"@semantic-release/git": "^10.0.1",
|
|
81
|
-
"@semantic-release/github": "^
|
|
82
|
-
"@semantic-release/npm": "^
|
|
83
|
-
"@testing-library/dom": "^
|
|
84
|
-
"@testing-library/jest-dom": "^6.
|
|
85
|
-
"@testing-library/react": "^
|
|
86
|
-
"@testing-library/
|
|
87
|
-
"@types/jest": "^29.5.
|
|
88
|
-
"@types/node": "^20.
|
|
89
|
-
"@types/react": "^
|
|
90
|
-
"@
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"eslint
|
|
94
|
-
"eslint-plugin-
|
|
95
|
-
"eslint-plugin-react
|
|
96
|
-
"
|
|
109
|
+
"@semantic-release/github": "^9.2.6",
|
|
110
|
+
"@semantic-release/npm": "^11.0.2",
|
|
111
|
+
"@testing-library/dom": "^9.3.4",
|
|
112
|
+
"@testing-library/jest-dom": "^6.4.2",
|
|
113
|
+
"@testing-library/react": "^14.2.1",
|
|
114
|
+
"@testing-library/user-event": "^14.5.2",
|
|
115
|
+
"@types/jest": "^29.5.12",
|
|
116
|
+
"@types/node": "^20.11.24",
|
|
117
|
+
"@types/react": "^18.2.61",
|
|
118
|
+
"@types/react-dom": "^18.2.19",
|
|
119
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
120
|
+
"commitlint": "^19.0.3",
|
|
121
|
+
"eslint": "^8.57.0",
|
|
122
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
123
|
+
"eslint-plugin-react": "^7.33.2",
|
|
124
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
125
|
+
"husky": "^9.0.11",
|
|
97
126
|
"jest": "^29.7.0",
|
|
98
|
-
"jest-environment-jsdom": "^
|
|
99
|
-
"lint-staged": "^
|
|
100
|
-
"
|
|
101
|
-
"react
|
|
102
|
-
"
|
|
127
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
128
|
+
"lint-staged": "^15.2.2",
|
|
129
|
+
"prettier": "^3.2.5",
|
|
130
|
+
"react": "^18.2.0",
|
|
131
|
+
"react-dom": "^18.2.0",
|
|
132
|
+
"rollup": "^4.12.0",
|
|
103
133
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
104
|
-
"semantic-release": "^
|
|
105
|
-
"ts-jest": "^29.
|
|
106
|
-
"typescript": "
|
|
107
|
-
"typescript-eslint": "^
|
|
134
|
+
"semantic-release": "^23.0.2",
|
|
135
|
+
"ts-jest": "^29.1.2",
|
|
136
|
+
"typescript": "^5.3.3",
|
|
137
|
+
"typescript-eslint": "^7.0.2"
|
|
108
138
|
}
|
|
109
139
|
}
|
package/rollup.config.mjs
CHANGED
|
@@ -13,7 +13,7 @@ const external = [
|
|
|
13
13
|
/^react-dom\//,
|
|
14
14
|
'typescript',
|
|
15
15
|
'tslib',
|
|
16
|
-
'@babel/runtime'
|
|
16
|
+
'@babel/runtime',
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
export default {
|
|
@@ -28,9 +28,9 @@ export default {
|
|
|
28
28
|
'react-dom': 'ReactDOM',
|
|
29
29
|
typescript: 'ts',
|
|
30
30
|
tslib: 'tslib',
|
|
31
|
-
'@babel/runtime': 'babelRuntime'
|
|
31
|
+
'@babel/runtime': 'babelRuntime',
|
|
32
32
|
},
|
|
33
|
-
exports: 'named'
|
|
33
|
+
exports: 'named',
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
file: 'dist/index.cjs.js',
|
|
@@ -41,52 +41,58 @@ export default {
|
|
|
41
41
|
'react-dom': 'ReactDOM',
|
|
42
42
|
typescript: 'ts',
|
|
43
43
|
tslib: 'tslib',
|
|
44
|
-
'@babel/runtime': 'babelRuntime'
|
|
44
|
+
'@babel/runtime': 'babelRuntime',
|
|
45
45
|
},
|
|
46
|
-
exports: 'named'
|
|
46
|
+
exports: 'named',
|
|
47
47
|
},
|
|
48
48
|
],
|
|
49
49
|
plugins: [
|
|
50
50
|
peerDepsExternal({
|
|
51
|
-
includeDependencies: false
|
|
51
|
+
includeDependencies: false,
|
|
52
52
|
}),
|
|
53
53
|
resolve({
|
|
54
54
|
mainFields: ['module', 'main'],
|
|
55
55
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
56
56
|
preferBuiltins: true,
|
|
57
|
-
dedupe: ['react', 'react-dom']
|
|
57
|
+
dedupe: ['react', 'react-dom'],
|
|
58
58
|
}),
|
|
59
59
|
commonjs({
|
|
60
60
|
include: /node_modules/,
|
|
61
61
|
transformMixedEsModules: true,
|
|
62
|
-
requireReturnsDefault: 'auto'
|
|
62
|
+
requireReturnsDefault: 'auto',
|
|
63
63
|
}),
|
|
64
|
-
typescript({
|
|
64
|
+
typescript({
|
|
65
65
|
tsconfig: './tsconfig.json',
|
|
66
66
|
exclude: ['**/__tests__/**', '**/*.test.ts', '**/*.test.tsx'],
|
|
67
67
|
declaration: true,
|
|
68
68
|
declarationDir: './dist',
|
|
69
69
|
emitDeclarationOnly: false,
|
|
70
|
-
sourceMap: true
|
|
70
|
+
sourceMap: true,
|
|
71
71
|
}),
|
|
72
72
|
babel({
|
|
73
73
|
babelHelpers: 'runtime',
|
|
74
74
|
presets: [
|
|
75
|
-
[
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
[
|
|
76
|
+
'@babel/preset-react',
|
|
77
|
+
{
|
|
78
|
+
runtime: 'automatic',
|
|
79
|
+
development: process.env.NODE_ENV === 'development',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
79
82
|
],
|
|
80
83
|
plugins: [
|
|
81
|
-
[
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
[
|
|
85
|
+
'@babel/plugin-transform-runtime',
|
|
86
|
+
{
|
|
87
|
+
regenerator: true,
|
|
88
|
+
useESModules: true,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
85
91
|
],
|
|
86
92
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
87
|
-
exclude: 'node_modules/**'
|
|
93
|
+
exclude: 'node_modules/**',
|
|
88
94
|
}),
|
|
89
|
-
terser()
|
|
95
|
+
terser(),
|
|
90
96
|
],
|
|
91
|
-
external
|
|
97
|
+
external,
|
|
92
98
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import { useBroadcastChannel } from './hooks/useBroadcastChannel';
|
|
2
|
+
import { useBroadcastChannel } from './hooks/useBroadcastChannel';
|
|
3
3
|
import { BroadcastMessage } from './types/types';
|
|
4
4
|
|
|
5
5
|
interface BroadcastContextValue {
|
|
@@ -39,14 +39,16 @@ interface BroadcastProviderProps {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export const BroadcastProvider: React.FC<BroadcastProviderProps> = ({ children, channelName }) => {
|
|
42
|
-
const { messages, error: hookError } = useBroadcastChannel(channelName);
|
|
42
|
+
const { messages, error: hookError } = useBroadcastChannel(channelName);
|
|
43
43
|
|
|
44
44
|
const [error, setError] = React.useState<string | null>(null);
|
|
45
45
|
const channel = useRef<BroadcastChannel | null>(null);
|
|
46
46
|
|
|
47
47
|
useEffect(() => {
|
|
48
48
|
if (typeof BroadcastChannel === 'undefined') {
|
|
49
|
-
setError(
|
|
49
|
+
setError(
|
|
50
|
+
'BroadcastChannel is not supported in this browser. Please check browser compatibility.'
|
|
51
|
+
);
|
|
50
52
|
return;
|
|
51
53
|
}
|
|
52
54
|
const bc = new BroadcastChannel(channelName);
|
|
@@ -64,9 +66,7 @@ export const BroadcastProvider: React.FC<BroadcastProviderProps> = ({ children,
|
|
|
64
66
|
|
|
65
67
|
return (
|
|
66
68
|
<ErrorBoundary>
|
|
67
|
-
<BroadcastChannelContext.Provider value={value}>
|
|
68
|
-
{children}
|
|
69
|
-
</BroadcastChannelContext.Provider>
|
|
69
|
+
<BroadcastChannelContext.Provider value={value}>{children}</BroadcastChannelContext.Provider>
|
|
70
70
|
</ErrorBoundary>
|
|
71
71
|
);
|
|
72
72
|
};
|