From 5510757ffedd1b2b23e66e5220f3412a212f2a81 Mon Sep 17 00:00:00 2001 From: devrnt Date: Sat, 8 Feb 2025 15:41:49 +0100 Subject: [PATCH 1/9] Bring back react hook linter plugin --- eslint.config.js | 3 + package.json | 1 + pnpm-lock.yaml | 143 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 145 insertions(+), 2 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index b55fd5d..03dcfa5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,6 +1,7 @@ import eslint from '@eslint/js'; import prettierConfig from 'eslint-config-prettier'; import reactPlugin from 'eslint-plugin-react'; +import reactHooks from 'eslint-plugin-react-hooks'; import simpleImportSort from 'eslint-plugin-simple-import-sort'; import tseslint from 'typescript-eslint'; @@ -12,6 +13,7 @@ export default tseslint.config( files: ['**/*.{js,jsx,ts,tsx}'], plugins: { react: reactPlugin, + 'react-hooks': reactHooks, 'simple-import-sort': simpleImportSort, }, languageOptions: { @@ -27,6 +29,7 @@ export default tseslint.config( }, }, rules: { + ...reactHooks.configs.recommended.rules, 'simple-import-sort/imports': 'error', 'sort-imports': 'off', 'import/order': 'off', diff --git a/package.json b/package.json index 3686bcf..acbda33 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "eslint": "^9.20.0", "eslint-config-prettier": "^10.0.1", "eslint-plugin-prettier": "^5.2.3", + "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-simple-import-sort": "^12.1.1", "prettier": "^3.4.2", "turbo": "^2.4.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79e289c..f1f9130 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: eslint-plugin-prettier: specifier: ^5.2.3 version: 5.2.3(@types/eslint@9.6.1)(eslint-config-prettier@10.0.1(eslint@9.20.0))(eslint@9.20.0)(prettier@3.4.2) + eslint-plugin-react-hooks: + specifier: ^5.0.0 + version: 5.1.0(eslint@9.20.0) eslint-plugin-simple-import-sort: specifier: ^12.1.1 version: 12.1.1(eslint@9.20.0) @@ -188,7 +191,7 @@ importers: version: 2.8.1 tsup: specifier: ^8.3.6 - version: 8.3.6(postcss@8.5.1)(typescript@5.7.3)(yaml@2.7.0) + version: 8.3.6(@swc/core@1.10.15(@swc/helpers@0.5.5))(postcss@8.5.1)(typescript@5.7.3)(yaml@2.7.0) typescript: specifier: ^5.7.3 version: 5.7.3 @@ -2200,6 +2203,75 @@ packages: '@socket.io/component-emitter@3.1.2': resolution: {integrity: sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==} + '@swc/core-darwin-arm64@1.10.15': + resolution: {integrity: sha512-zFdZ6/yHqMCPk7OhLFqHy/MQ1EqJhcZMpNHd1gXYT7VRU3FaqvvKETrUlG3VYl65McPC7AhMRfXPyJ0JO/jARQ==} + engines: {node: '>=10'} + cpu: [arm64] + os: [darwin] + + '@swc/core-darwin-x64@1.10.15': + resolution: {integrity: sha512-8g4yiQwbr8fxOOjKXdot0dEkE5zgE8uNZudLy/ZyAhiwiZ8pbJ8/wVrDOu6dqbX7FBXAoDnvZ7fwN1jk4C8jdA==} + engines: {node: '>=10'} + cpu: [x64] + os: [darwin] + + '@swc/core-linux-arm-gnueabihf@1.10.15': + resolution: {integrity: sha512-rl+eVOltl2+7WXOnvmWBpMgh6aO13G5x0U0g8hjwlmD6ku3Y9iRcThpOhm7IytMEarUp5pQxItNoPq+VUGjVHg==} + engines: {node: '>=10'} + cpu: [arm] + os: [linux] + + '@swc/core-linux-arm64-gnu@1.10.15': + resolution: {integrity: sha512-qxWEQeyAJMWJqjaN4hi58WMpPdt3Tn0biSK9CYRegQtvZWCbewr6v2agtSu5AZ2rudeH6OfCWAMDQQeSgn6PJQ==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + + '@swc/core-linux-arm64-musl@1.10.15': + resolution: {integrity: sha512-QcELd9/+HjZx0WCxRrKcyKGWTiQ0485kFb5w8waxcSNd0d9Lgk4EFfWWVyvIb5gIHpDQmhrgzI/yRaWQX4YSZQ==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + + '@swc/core-linux-x64-gnu@1.10.15': + resolution: {integrity: sha512-S1+ZEEn3+a/MiMeQqQypbwTGoBG8/sPoCvpNbk+uValyygT+jSn3U0xVr45FbukpmMB+NhBMqfedMLqKA0QnJA==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + + '@swc/core-linux-x64-musl@1.10.15': + resolution: {integrity: sha512-qW+H9g/2zTJ4jP7NDw4VAALY0ZlNEKzYsEoSj/HKi7k3tYEHjMzsxjfsY9I8WZCft23bBdV3RTCPoxCshaj1CQ==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + + '@swc/core-win32-arm64-msvc@1.10.15': + resolution: {integrity: sha512-AhRB11aA6LxjIqut+mg7qsu/7soQDmbK6MKR9nP3hgBszpqtXbRba58lr24xIbBCMr+dpo6kgEapWt+t5Po6Zg==} + engines: {node: '>=10'} + cpu: [arm64] + os: [win32] + + '@swc/core-win32-ia32-msvc@1.10.15': + resolution: {integrity: sha512-UGdh430TQwbDn6KjgvRTg1fO022sbQ4yCCHUev0+5B8uoBwi9a89qAz3emy2m56C8TXxUoihW9Y9OMfaRwPXUw==} + engines: {node: '>=10'} + cpu: [ia32] + os: [win32] + + '@swc/core-win32-x64-msvc@1.10.15': + resolution: {integrity: sha512-XJzBCqO1m929qbJsOG7FZXQWX26TnEoMctS3QjuCoyBmkHxxQmZsy78KjMes1aomTcKHCyFYgrRGWgVmk7tT4Q==} + engines: {node: '>=10'} + cpu: [x64] + os: [win32] + + '@swc/core@1.10.15': + resolution: {integrity: sha512-/iFeQuNaGdK7mfJbQcObhAhsMqLT7qgMYl7jX2GEIO+VDTejESpzAyKwaMeYXExN8D6e5BRHBCe7M5YlsuzjDA==} + engines: {node: '>=10'} + peerDependencies: + '@swc/helpers': '*' + peerDependenciesMeta: + '@swc/helpers': + optional: true + '@swc/counter@0.1.3': resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} @@ -2215,6 +2287,9 @@ packages: '@swc/helpers@0.5.5': resolution: {integrity: sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==} + '@swc/types@0.1.17': + resolution: {integrity: sha512-V5gRru+aD8YVyCOMAjMpWR1Ui577DD5KSJsHP8RAxopAH22jFz6GZd/qxqjO6MJHQhcsjvjOFXyDhyLQUnMveQ==} + '@szmarczak/http-timer@4.0.6': resolution: {integrity: sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==} engines: {node: '>=10'} @@ -4155,6 +4230,12 @@ packages: peerDependencies: eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 + eslint-plugin-react-hooks@5.1.0: + resolution: {integrity: sha512-mpJRtPgHN2tNAvZ35AMfqeB3Xqeo273QxrHJsbBEPWODRM4r0yB6jfoROqKEYrOn27UtRPpcpHc2UqyBSuUNTw==} + engines: {node: '>=10'} + peerDependencies: + eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 + eslint-plugin-react@7.37.4: resolution: {integrity: sha512-BGP0jRmfYyvOyvMoRX/uoUeW+GqNj9y16bPQzqAHf3AYII/tDs+jMN0dBVkl88/OZwNGwrVFxE7riHsXVfy/LQ==} engines: {node: '>=4'} @@ -10506,6 +10587,54 @@ snapshots: '@socket.io/component-emitter@3.1.2': {} + '@swc/core-darwin-arm64@1.10.15': + optional: true + + '@swc/core-darwin-x64@1.10.15': + optional: true + + '@swc/core-linux-arm-gnueabihf@1.10.15': + optional: true + + '@swc/core-linux-arm64-gnu@1.10.15': + optional: true + + '@swc/core-linux-arm64-musl@1.10.15': + optional: true + + '@swc/core-linux-x64-gnu@1.10.15': + optional: true + + '@swc/core-linux-x64-musl@1.10.15': + optional: true + + '@swc/core-win32-arm64-msvc@1.10.15': + optional: true + + '@swc/core-win32-ia32-msvc@1.10.15': + optional: true + + '@swc/core-win32-x64-msvc@1.10.15': + optional: true + + '@swc/core@1.10.15(@swc/helpers@0.5.5)': + dependencies: + '@swc/counter': 0.1.3 + '@swc/types': 0.1.17 + optionalDependencies: + '@swc/core-darwin-arm64': 1.10.15 + '@swc/core-darwin-x64': 1.10.15 + '@swc/core-linux-arm-gnueabihf': 1.10.15 + '@swc/core-linux-arm64-gnu': 1.10.15 + '@swc/core-linux-arm64-musl': 1.10.15 + '@swc/core-linux-x64-gnu': 1.10.15 + '@swc/core-linux-x64-musl': 1.10.15 + '@swc/core-win32-arm64-msvc': 1.10.15 + '@swc/core-win32-ia32-msvc': 1.10.15 + '@swc/core-win32-x64-msvc': 1.10.15 + '@swc/helpers': 0.5.5 + optional: true + '@swc/counter@0.1.3': {} '@swc/helpers@0.4.14': @@ -10526,6 +10655,11 @@ snapshots: '@swc/counter': 0.1.3 tslib: 2.8.1 + '@swc/types@0.1.17': + dependencies: + '@swc/counter': 0.1.3 + optional: true + '@szmarczak/http-timer@4.0.6': dependencies: defer-to-connect: 2.0.1 @@ -12924,6 +13058,10 @@ snapshots: dependencies: eslint: 7.32.0 + eslint-plugin-react-hooks@5.1.0(eslint@9.20.0): + dependencies: + eslint: 9.20.0 + eslint-plugin-react@7.37.4(eslint@7.32.0): dependencies: array-includes: 3.1.8 @@ -17214,7 +17352,7 @@ snapshots: tslib@2.8.1: {} - tsup@8.3.6(postcss@8.5.1)(typescript@5.7.3)(yaml@2.7.0): + tsup@8.3.6(@swc/core@1.10.15(@swc/helpers@0.5.5))(postcss@8.5.1)(typescript@5.7.3)(yaml@2.7.0): dependencies: bundle-require: 5.1.0(esbuild@0.24.2) cac: 6.7.14 @@ -17233,6 +17371,7 @@ snapshots: tinyglobby: 0.2.10 tree-kill: 1.2.2 optionalDependencies: + '@swc/core': 1.10.15(@swc/helpers@0.5.5) postcss: 8.5.1 typescript: 5.7.3 transitivePeerDependencies: From 47045eb893ef1deb35a891ca2aa366bc34d17465 Mon Sep 17 00:00:00 2001 From: devrnt Date: Sat, 8 Feb 2025 21:13:32 +0100 Subject: [PATCH 2/9] Change order exports in package.json --- packages/react-use-intercom/package.json | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/react-use-intercom/package.json b/packages/react-use-intercom/package.json index 0f1d62f..d0c0d25 100644 --- a/packages/react-use-intercom/package.json +++ b/packages/react-use-intercom/package.json @@ -22,14 +22,13 @@ ], "exports": { ".": { - "browser": "./dist/index.js", - "require": { - "types": "./dist/index.d.cts", - "default": "./dist/index.cjs" - }, "import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" + }, + "require": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" } } }, @@ -95,4 +94,4 @@ "tsup": "^8.3.6", "typescript": "^5.7.3" } -} \ No newline at end of file +} From 6986ffe19173e6a6c7efba5dbb49d1bd2f0089c6 Mon Sep 17 00:00:00 2001 From: devrnt Date: Sat, 8 Feb 2025 21:14:01 +0100 Subject: [PATCH 3/9] Add vite example for reproduction --- apps/examples/vite/.gitignore | 24 ++++ apps/examples/vite/README.md | 3 + apps/examples/vite/eslint.config.js | 38 ++++++ apps/examples/vite/index.html | 13 ++ apps/examples/vite/package.json | 29 +++++ apps/examples/vite/src/app.jsx | 43 +++++++ apps/examples/vite/src/main.jsx | 10 ++ apps/examples/vite/vite.config.js | 8 ++ pnpm-lock.yaml | 182 +++++++++++++++++++++++++++- 9 files changed, 348 insertions(+), 2 deletions(-) create mode 100644 apps/examples/vite/.gitignore create mode 100644 apps/examples/vite/README.md create mode 100644 apps/examples/vite/eslint.config.js create mode 100644 apps/examples/vite/index.html create mode 100644 apps/examples/vite/package.json create mode 100644 apps/examples/vite/src/app.jsx create mode 100644 apps/examples/vite/src/main.jsx create mode 100644 apps/examples/vite/vite.config.js diff --git a/apps/examples/vite/.gitignore b/apps/examples/vite/.gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/apps/examples/vite/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/apps/examples/vite/README.md b/apps/examples/vite/README.md new file mode 100644 index 0000000..7731a54 --- /dev/null +++ b/apps/examples/vite/README.md @@ -0,0 +1,3 @@ +# react-use-intercom in a Vite app + +Replace `INTERCOM_APP_ID` with your Intercom app id. diff --git a/apps/examples/vite/eslint.config.js b/apps/examples/vite/eslint.config.js new file mode 100644 index 0000000..238d2e4 --- /dev/null +++ b/apps/examples/vite/eslint.config.js @@ -0,0 +1,38 @@ +import js from '@eslint/js' +import globals from 'globals' +import react from 'eslint-plugin-react' +import reactHooks from 'eslint-plugin-react-hooks' +import reactRefresh from 'eslint-plugin-react-refresh' + +export default [ + { ignores: ['dist'] }, + { + files: ['**/*.{js,jsx}'], + languageOptions: { + ecmaVersion: 2020, + globals: globals.browser, + parserOptions: { + ecmaVersion: 'latest', + ecmaFeatures: { jsx: true }, + sourceType: 'module', + }, + }, + settings: { react: { version: '18.3' } }, + plugins: { + react, + 'react-hooks': reactHooks, + 'react-refresh': reactRefresh, + }, + rules: { + ...js.configs.recommended.rules, + ...react.configs.recommended.rules, + ...react.configs['jsx-runtime'].rules, + ...reactHooks.configs.recommended.rules, + 'react/jsx-no-target-blank': 'off', + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, + }, +] diff --git a/apps/examples/vite/index.html b/apps/examples/vite/index.html new file mode 100644 index 0000000..0c589ec --- /dev/null +++ b/apps/examples/vite/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + React + + +
+ + + diff --git a/apps/examples/vite/package.json b/apps/examples/vite/package.json new file mode 100644 index 0000000..b444ba2 --- /dev/null +++ b/apps/examples/vite/package.json @@ -0,0 +1,29 @@ +{ + "name": "vite-example", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "lint": "eslint .", + "preview": "vite preview" + }, + "dependencies": { + "react": "^19.0.0", + "react-dom": "^19.0.0", + "react-use-intercom": "*" + }, + "devDependencies": { + "@eslint/js": "^9.19.0", + "@types/react": "^19.0.8", + "@types/react-dom": "^19.0.3", + "@vitejs/plugin-react-swc": "^3.5.0", + "eslint": "^9.19.0", + "eslint-plugin-react": "^7.37.4", + "eslint-plugin-react-hooks": "^5.0.0", + "eslint-plugin-react-refresh": "^0.4.18", + "globals": "^15.14.0", + "vite": "^6.1.0" + } +} diff --git a/apps/examples/vite/src/app.jsx b/apps/examples/vite/src/app.jsx new file mode 100644 index 0000000..1245c54 --- /dev/null +++ b/apps/examples/vite/src/app.jsx @@ -0,0 +1,43 @@ +import { useEffect } from 'react'; +import { IntercomProvider, useIntercom } from 'react-use-intercom'; + +const INTERCOM_APP_ID = 'jcabc7e3'; + +export function App() { + return ( + alert('show')} + > + + + ); +} + +function OurApp() { + return ( +
+

Our App

+ +
+ ); +} + +function TrackEvent() { + const { trackEvent, boot, shutdown } = useIntercom(); + + useEffect(() => { + trackEvent('event'); + }, [trackEvent]); + + return ( + <> +

Tracing event in effect

+ + + + ); +} + +export default App; diff --git a/apps/examples/vite/src/main.jsx b/apps/examples/vite/src/main.jsx new file mode 100644 index 0000000..5f0c5eb --- /dev/null +++ b/apps/examples/vite/src/main.jsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react'; +import { createRoot } from 'react-dom/client'; + +import { App } from './app.jsx'; + +createRoot(document.getElementById('root')).render( + + + , +); diff --git a/apps/examples/vite/vite.config.js b/apps/examples/vite/vite.config.js new file mode 100644 index 0000000..aaab054 --- /dev/null +++ b/apps/examples/vite/vite.config.js @@ -0,0 +1,8 @@ +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react-swc'; + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [react()], + clearScreen: false, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f1f9130..8d45040 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -90,6 +90,49 @@ importers: specifier: '*' version: link:../../../packages/react-use-intercom + apps/examples/vite: + dependencies: + react: + specifier: ^19.0.0 + version: 19.0.0 + react-dom: + specifier: ^19.0.0 + version: 19.0.0(react@19.0.0) + react-use-intercom: + specifier: '*' + version: link:../../../packages/react-use-intercom + devDependencies: + '@eslint/js': + specifier: ^9.19.0 + version: 9.20.0 + '@types/react': + specifier: ^19.0.8 + version: 19.0.8 + '@types/react-dom': + specifier: ^19.0.3 + version: 19.0.3(@types/react@19.0.8) + '@vitejs/plugin-react-swc': + specifier: ^3.5.0 + version: 3.7.2(@swc/helpers@0.5.5)(vite@6.1.0(@types/node@18.19.75)(terser@5.38.1)(yaml@2.7.0)) + eslint: + specifier: ^9.19.0 + version: 9.20.0 + eslint-plugin-react: + specifier: ^7.37.4 + version: 7.37.4(eslint@9.20.0) + eslint-plugin-react-hooks: + specifier: ^5.0.0 + version: 5.1.0(eslint@9.20.0) + eslint-plugin-react-refresh: + specifier: ^0.4.18 + version: 0.4.18(eslint@9.20.0) + globals: + specifier: ^15.14.0 + version: 15.14.0 + vite: + specifier: ^6.1.0 + version: 6.1.0(@types/node@18.19.75)(terser@5.38.1)(yaml@2.7.0) + apps/playground: dependencies: react: @@ -2442,6 +2485,11 @@ packages: peerDependencies: '@types/react': ^18.0.0 + '@types/react-dom@19.0.3': + resolution: {integrity: sha512-0Knk+HJiMP/qOZgMyNFamlIjw9OFCsyC2ZbigmEEyXXixgre6IQpm/4V+r3qH4GC1JPvRJKInw+on2rV6YZLeA==} + peerDependencies: + '@types/react': ^19.0.0 + '@types/react-router-dom@5.3.3': resolution: {integrity: sha512-kpqnYK4wcdm5UaWI3fLcELopqLrHgLqNsdpHauzlQktfkHL3npOSwtj1Uz9oKBAzs7lFtVkV8j83voAz2D8fhw==} @@ -2451,6 +2499,9 @@ packages: '@types/react@18.3.18': resolution: {integrity: sha512-t4yC+vtgnkYjNSKlFx1jkAhH8LgTo2N/7Qvi83kdEaUtMDiwpbLAktKDaAMlRcJ5eSxZkH74eEGt1ky31d7kfQ==} + '@types/react@19.0.8': + resolution: {integrity: sha512-9P/o1IGdfmQxrujGbIMDyYaaCykhLKc0NGCtYcECNUr9UAaDe4gwvV9bR6tvd5Br1SG0j+PBpbKr2UYY8CwqSw==} + '@types/responselike@1.0.3': resolution: {integrity: sha512-H/+L+UkTV33uf49PH5pCAUBVPNj2nDBXTN+qS1dOwyyg24l3CcicicCA7ca+HMvJBZcFgl5r8e+RR6elsb4Lyw==} @@ -2598,6 +2649,11 @@ packages: '@vercel/webpack-asset-relocator-loader@1.7.3': resolution: {integrity: sha512-vizrI18v8Lcb1PmNNUBz7yxPxxXoOeuaVEjTG9MjvDrphjiSxFZrRJ5tIghk+qdLFRCXI5HBCshgobftbmrC5g==} + '@vitejs/plugin-react-swc@3.7.2': + resolution: {integrity: sha512-y0byko2b2tSVVf5Gpng1eEhX1OvPC7x8yns1Fx8jDzlJp4LS6CMkCPfLw47cjyoMrshQDoQw4qcgjsU9VvlCew==} + peerDependencies: + vite: ^4 || ^5 || ^6 + '@vitejs/plugin-react@3.1.0': resolution: {integrity: sha512-AfgcRL8ZBhAlc3BFdigClmTUMISmmzHn7sB2h9U1odvc5U/MjWXsAaz18b/WoppUTDBzxOJwo2VdClfUcItu9g==} engines: {node: ^14.18.0 || >=16.0.0} @@ -4236,6 +4292,11 @@ packages: peerDependencies: eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 + eslint-plugin-react-refresh@0.4.18: + resolution: {integrity: sha512-IRGEoFn3OKalm3hjfolEWGqoF/jPqeEYFp+C8B0WMzwGwBMvlRDQd06kghDhF0C61uJ6WfSDhEZE/sAQjduKgw==} + peerDependencies: + eslint: '>=8.40' + eslint-plugin-react@7.37.4: resolution: {integrity: sha512-BGP0jRmfYyvOyvMoRX/uoUeW+GqNj9y16bPQzqAHf3AYII/tDs+jMN0dBVkl88/OZwNGwrVFxE7riHsXVfy/LQ==} engines: {node: '>=4'} @@ -4816,6 +4877,10 @@ packages: resolution: {integrity: sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==} engines: {node: '>=18'} + globals@15.14.0: + resolution: {integrity: sha512-OkToC372DtlQeje9/zHIo5CT8lRP/FUgEOKBEhU4e0abL7J7CD24fD9ohiLN5hagG/kWCYj4K5oaxxtj2Z0Dig==} + engines: {node: '>=18'} + globalthis@1.0.4: resolution: {integrity: sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ==} engines: {node: '>= 0.4'} @@ -6805,6 +6870,11 @@ packages: peerDependencies: react: ^18.3.1 + react-dom@19.0.0: + resolution: {integrity: sha512-4GV5sHFG0e/0AD4X+ySy6UJd3jVl1iNsNHdpad0qhABJ11twS3TTBnseqsKurKcsNqCEFeGL3uLpVChpIO3QfQ==} + peerDependencies: + react: ^19.0.0 + react-error-overlay@6.0.11: resolution: {integrity: sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==} @@ -6852,6 +6922,10 @@ packages: resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==} engines: {node: '>=0.10.0'} + react@19.0.0: + resolution: {integrity: sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ==} + engines: {node: '>=0.10.0'} + read-yaml-file@1.1.0: resolution: {integrity: sha512-VIMnQi/Z4HT2Fxuwg5KrY174U1VdUIASQVWXXyqtNRtxSr9IYkn1rsI6Tb6HsrHCmB7gVpNwX6JxPTHcH6IoTA==} engines: {node: '>=6'} @@ -7090,6 +7164,9 @@ packages: scheduler@0.23.2: resolution: {integrity: sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==} + scheduler@0.25.0: + resolution: {integrity: sha512-xFVuu11jh+xcO7JOAGJNOXld8/TcEHK/4CituBUeUb5hqxJLj9YuemAEuvm9gQ/+pgXYfbQuqAkiYu+u7YEsNA==} + schema-utils@2.7.0: resolution: {integrity: sha512-0ilKFI6QQF5nxDZLFn2dMjvc4hjg/Wkg7rHd3jK6/A4a1Hl9VFdQWvgB1UMGoU94pad1P/8N7fMcEnLnSiju8A==} engines: {node: '>= 8.9.0'} @@ -7995,6 +8072,46 @@ packages: terser: optional: true + vite@6.1.0: + resolution: {integrity: sha512-RjjMipCKVoR4hVfPY6GQTgveinjNuyLw+qruksLDvA5ktI1150VmcMBKmQaEWJhg/j6Uaf6dNCNA0AfdzUb/hQ==} + engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} + hasBin: true + peerDependencies: + '@types/node': ^18.0.0 || ^20.0.0 || >=22.0.0 + jiti: '>=1.21.0' + less: '*' + lightningcss: ^1.21.0 + sass: '*' + sass-embedded: '*' + stylus: '*' + sugarss: '*' + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + '@types/node': + optional: true + jiti: + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + w3c-xmlserializer@4.0.0: resolution: {integrity: sha512-d+BFHzbiCx6zGfz0HyQ6Rg69w9k19nviJspaj4yNscGjrHu94sVP+aRm75yEbCh+r2/yR+7q6hux9LVtbuTGBw==} engines: {node: '>=14'} @@ -10633,7 +10750,6 @@ snapshots: '@swc/core-win32-ia32-msvc': 1.10.15 '@swc/core-win32-x64-msvc': 1.10.15 '@swc/helpers': 0.5.5 - optional: true '@swc/counter@0.1.3': {} @@ -10658,7 +10774,6 @@ snapshots: '@swc/types@0.1.17': dependencies: '@swc/counter': 0.1.3 - optional: true '@szmarczak/http-timer@4.0.6': dependencies: @@ -10835,6 +10950,10 @@ snapshots: dependencies: '@types/react': 18.3.18 + '@types/react-dom@19.0.3(@types/react@19.0.8)': + dependencies: + '@types/react': 19.0.8 + '@types/react-router-dom@5.3.3': dependencies: '@types/history': 4.7.11 @@ -10851,6 +10970,10 @@ snapshots: '@types/prop-types': 15.7.14 csstype: 3.1.3 + '@types/react@19.0.8': + dependencies: + csstype: 3.1.3 + '@types/responselike@1.0.3': dependencies: '@types/node': 18.19.75 @@ -11056,6 +11179,13 @@ snapshots: dependencies: resolve: 1.22.10 + '@vitejs/plugin-react-swc@3.7.2(@swc/helpers@0.5.5)(vite@6.1.0(@types/node@18.19.75)(terser@5.38.1)(yaml@2.7.0))': + dependencies: + '@swc/core': 1.10.15(@swc/helpers@0.5.5) + vite: 6.1.0(@types/node@18.19.75)(terser@5.38.1)(yaml@2.7.0) + transitivePeerDependencies: + - '@swc/helpers' + '@vitejs/plugin-react@3.1.0(vite@4.5.9(@types/node@18.19.75)(terser@5.38.1))': dependencies: '@babel/core': 7.26.7 @@ -13062,6 +13192,10 @@ snapshots: dependencies: eslint: 9.20.0 + eslint-plugin-react-refresh@0.4.18(eslint@9.20.0): + dependencies: + eslint: 9.20.0 + eslint-plugin-react@7.37.4(eslint@7.32.0): dependencies: array-includes: 3.1.8 @@ -13084,6 +13218,28 @@ snapshots: string.prototype.matchall: 4.0.12 string.prototype.repeat: 1.0.0 + eslint-plugin-react@7.37.4(eslint@9.20.0): + dependencies: + array-includes: 3.1.8 + array.prototype.findlast: 1.2.5 + array.prototype.flatmap: 1.3.3 + array.prototype.tosorted: 1.1.4 + doctrine: 2.1.0 + es-iterator-helpers: 1.2.1 + eslint: 9.20.0 + estraverse: 5.3.0 + hasown: 2.0.2 + jsx-ast-utils: 3.3.5 + minimatch: 3.1.2 + object.entries: 1.1.8 + object.fromentries: 2.0.8 + object.values: 1.2.1 + prop-types: 15.8.1 + resolve: 2.0.0-next.5 + semver: 6.3.1 + string.prototype.matchall: 4.0.12 + string.prototype.repeat: 1.0.0 + eslint-plugin-simple-import-sort@10.0.0(eslint@9.20.0): dependencies: eslint: 9.20.0 @@ -14099,6 +14255,8 @@ snapshots: globals@14.0.0: {} + globals@15.14.0: {} + globalthis@1.0.4: dependencies: define-properties: 1.2.1 @@ -16278,6 +16436,11 @@ snapshots: react: 18.3.1 scheduler: 0.23.2 + react-dom@19.0.0(react@19.0.0): + dependencies: + react: 19.0.0 + scheduler: 0.25.0 + react-error-overlay@6.0.11: {} react-is@16.13.1: {} @@ -16337,6 +16500,8 @@ snapshots: dependencies: loose-envify: 1.4.0 + react@19.0.0: {} + read-yaml-file@1.1.0: dependencies: graceful-fs: 4.2.11 @@ -16619,6 +16784,8 @@ snapshots: dependencies: loose-envify: 1.4.0 + scheduler@0.25.0: {} + schema-utils@2.7.0: dependencies: '@types/json-schema': 7.0.15 @@ -17604,6 +17771,17 @@ snapshots: fsevents: 2.3.3 terser: 5.38.1 + vite@6.1.0(@types/node@18.19.75)(terser@5.38.1)(yaml@2.7.0): + dependencies: + esbuild: 0.24.2 + postcss: 8.5.1 + rollup: 4.34.6 + optionalDependencies: + '@types/node': 18.19.75 + fsevents: 2.3.3 + terser: 5.38.1 + yaml: 2.7.0 + w3c-xmlserializer@4.0.0: dependencies: xml-name-validator: 4.0.0 From 74ad64c007c80e7e67beee50ded64640a2491174 Mon Sep 17 00:00:00 2001 From: devrnt Date: Sat, 8 Feb 2025 21:16:45 +0100 Subject: [PATCH 4/9] Move initialize and boot out of effect This reverts the changes from a6d77579a01b758d479a5e52f9453ba0058ef12b --- packages/react-use-intercom/src/provider.tsx | 51 ++++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/packages/react-use-intercom/src/provider.tsx b/packages/react-use-intercom/src/provider.tsx index 6145ef5..8a3392c 100644 --- a/packages/react-use-intercom/src/provider.tsx +++ b/packages/react-use-intercom/src/provider.tsx @@ -49,16 +49,6 @@ export const IntercomProvider: React.FC< ); } - const onHideWrapper = React.useCallback(() => { - setIsOpen(false); - if (onHide) onHide(); - }, [onHide, setIsOpen]); - - const onShowWrapper = React.useCallback(() => { - setIsOpen(true); - if (onShow) onShow(); - }, [onShow, setIsOpen]); - const boot = React.useCallback( (props?: IntercomProps) => { if (!window.Intercom && !shouldInitialize) { @@ -69,15 +59,26 @@ export const IntercomProvider: React.FC< return; } - // Attach the listeners + if (isBooted.current) { + return; + } + + // Register the listeners // This is done in the booth method because after shutting down - // the callbacks should be re-registered - IntercomAPI('onHide', onHideWrapper); - IntercomAPI('onShow', onShowWrapper); + // the callbacks should be re-registered on a reboot + IntercomAPI('onHide', () => { + setIsOpen(false); + onHide?.(); + }); + IntercomAPI('onShow', () => { + setIsOpen(true); + onShow?.(); + }); IntercomAPI('onUserEmailSupplied', onUserEmailSupplied); - if (onUnreadCountChange) + if (onUnreadCountChange) { IntercomAPI('onUnreadCountChange', onUnreadCountChange); + } const metaData: RawIntercomBootProps = { app_id: appId, @@ -92,25 +93,23 @@ export const IntercomProvider: React.FC< [ apiBase, appId, - onHideWrapper, - onShowWrapper, + onHide, + onShow, onUnreadCountChange, onUserEmailSupplied, shouldInitialize, ], ); - React.useEffect(() => { - if (!isSSR && shouldInitialize && !isInitialized.current) { - initialize(appId, initializeDelay); - - if (autoBoot) { - boot(autoBootProps); - } + if (!isSSR && shouldInitialize && !isInitialized.current) { + initialize(appId, initializeDelay); - isInitialized.current = true; + if (autoBoot) { + boot(autoBootProps); } - }, [appId, autoBoot, autoBootProps, boot, initializeDelay, shouldInitialize]); + + isInitialized.current = true; + } const ensureIntercom = React.useCallback( (functionName: string, callback: (() => void) | (() => string)) => { From db83ea1d7efcc76355f519a62acc2d5e79df7532 Mon Sep 17 00:00:00 2001 From: devrnt Date: Sat, 8 Feb 2025 21:19:28 +0100 Subject: [PATCH 5/9] Drop dependabot config --- .github/dependabot.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 9cfac3e..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,27 +0,0 @@ -version: 2 -updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - time: "04:00" - open-pull-requests-limit: 10 - ignore: - - dependency-name: cypress - versions: - - 6.3.0 - - 6.7.1 - - 7.0.0 - - dependency-name: "@types/react" - versions: - - 17.0.3 - - dependency-name: husky - versions: - - 5.1.0 - - 5.1.2 - - dependency-name: np - versions: - - 7.4.0 - - dependency-name: typescript - versions: - - 4.1.4 From 1b33f924e5dfc4af7d79c724a8eb4f25bfc74d16 Mon Sep 17 00:00:00 2001 From: devrnt Date: Sat, 8 Feb 2025 21:27:22 +0100 Subject: [PATCH 6/9] Update port vite example --- apps/examples/vite/vite.config.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/examples/vite/vite.config.js b/apps/examples/vite/vite.config.js index aaab054..7feb336 100644 --- a/apps/examples/vite/vite.config.js +++ b/apps/examples/vite/vite.config.js @@ -3,6 +3,9 @@ import react from '@vitejs/plugin-react-swc'; // https://vite.dev/config/ export default defineConfig({ + server: { + port: 9300, + }, plugins: [react()], clearScreen: false, }); From 439bb0361bb38538022b8a0c90c91f7d8d55aa44 Mon Sep 17 00:00:00 2001 From: devrnt Date: Sat, 8 Feb 2025 21:31:38 +0100 Subject: [PATCH 7/9] Remove outdated test --- apps/playground/cypress/e2e/boot.ts | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/apps/playground/cypress/e2e/boot.ts b/apps/playground/cypress/e2e/boot.ts index 2e88612..3b8b87f 100644 --- a/apps/playground/cypress/e2e/boot.ts +++ b/apps/playground/cypress/e2e/boot.ts @@ -53,31 +53,4 @@ describe('boot', () => { cy.get('[data-cy=show]').click(); cy.get('.intercom-lightweight-app-launcher-icon-open').should('not.exist'); }); - - it('should allow calling `boot` multiple times', () => { - cy.get('[data-cy=boot]').click(); - - // Wait for the route aliased as 'intercomPing' to respond - // without changing or stubbing its response - cy.wait('@intercomPing'); - - cy.get('.intercom-lightweight-app-launcher-icon-open').should('exist'); - cy.window().should('have.property', 'Intercom'); - cy.window().should('have.deep.property', 'intercomSettings', { - app_id: 'jcabc7e3', - }); - - cy.get('[data-cy="boot-seeded"]').click(); - - // Wait for the route aliased as 'intercomPing' to respond - // without changing or stubbing its response - cy.wait('@intercomPing'); - - cy.get('.intercom-lightweight-app-launcher-icon-open').should('exist'); - cy.window().should('have.property', 'Intercom'); - cy.window().should('have.deep.property', 'intercomSettings', { - app_id: 'jcabc7e3', - name: 'Russo', - }); - }); }); From 1a602b761fe20cb58ef3116efd8a86ec810b3440 Mon Sep 17 00:00:00 2001 From: devrnt Date: Sat, 8 Feb 2025 21:34:09 +0100 Subject: [PATCH 8/9] Update patter for sized action --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 15fad74..a004509 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -29,4 +29,4 @@ jobs: - uses: preactjs/compressed-size-action@v2 with: repo-token: '${{ secrets.GITHUB_TOKEN }}' - pattern: "packages/**/dist/**/*.?(m)js" + pattern: "packages/**/dist/**/*.?(c)js" From fec62332e000d29e13b7ebd60fd2e8f226b5dafd Mon Sep 17 00:00:00 2001 From: devrnt Date: Sat, 8 Feb 2025 21:35:10 +0100 Subject: [PATCH 9/9] Add changeset --- .changeset/little-bikes-itch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/little-bikes-itch.md diff --git a/.changeset/little-bikes-itch.md b/.changeset/little-bikes-itch.md new file mode 100644 index 0000000..c6e09af --- /dev/null +++ b/.changeset/little-bikes-itch.md @@ -0,0 +1,5 @@ +--- +'react-use-intercom': patch +--- + +Fix initializing intercom api