From 3a712166d0d4ceb0418ab131be574063af224015 Mon Sep 17 00:00:00 2001 From: ivliu Date: Mon, 4 Mar 2024 17:50:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20server=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +-- pnpm-lock.yaml | 64 ++++++++++++++++++++++++------------------------ src/Activity.tsx | 4 ++- src/Repeater.tsx | 5 +++- src/canUseDOM.ts | 6 +++++ 5 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 src/canUseDOM.ts diff --git a/package.json b/package.json index a00f42c..17df17b 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ ], "devDependencies": { "@size-limit/preset-small-lib": "^8.2.4", - "@types/react": "^18.2.57", + "@types/react": "^18.2.61", "@types/react-dom": "^18.2.19", "husky": "^8.0.3", "react": "^18.2.0", @@ -65,6 +65,6 @@ "size-limit": "^8.2.4", "tsdx": "^0.14.1", "tslib": "^2.5.0", - "typescript": "^5.0.4" + "typescript": "^5.3.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed3387e..c23ff37 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ devDependencies: specifier: ^8.2.4 version: 8.2.4(size-limit@8.2.4) '@types/react': - specifier: ^18.2.57 - version: 18.2.57 + specifier: ^18.2.61 + version: 18.2.61 '@types/react-dom': specifier: ^18.2.19 version: 18.2.19 @@ -33,8 +33,8 @@ devDependencies: specifier: ^2.5.0 version: 2.5.0 typescript: - specifier: ^5.0.4 - version: 5.0.4 + specifier: ^5.3.3 + version: 5.3.3 packages: @@ -1910,11 +1910,11 @@ packages: /@types/react-dom@18.2.19: resolution: {integrity: sha512-aZvQL6uUbIJpjZk4U8JZGbau9KDeAwMfmhyWorxgBkqDIEf6ROjRozcmPIicqsUwPUjbkDfHKgGee1Lq65APcA==} dependencies: - '@types/react': 18.2.57 + '@types/react': 18.2.61 dev: true - /@types/react@18.2.57: - resolution: {integrity: sha512-ZvQsktJgSYrQiMirAN60y4O/LRevIV8hUzSOSNB6gfR3/o3wCBFQx3sPwIYtuDMeiVgsSS3UzCV26tEzgnfvQw==} + /@types/react@18.2.61: + resolution: {integrity: sha512-NURTN0qNnJa7O/k4XUkEW2yfygA+NxS0V5h1+kp9jPwhzZy95q3ADoGMP0+JypMhrZBTTgjKAUlTctde1zzeQA==} dependencies: '@types/prop-types': 15.7.5 '@types/scheduler': 0.16.3 @@ -1945,7 +1945,7 @@ packages: '@types/yargs-parser': 21.0.0 dev: true - /@typescript-eslint/eslint-plugin@2.34.0(@typescript-eslint/parser@2.34.0)(eslint@6.8.0)(typescript@5.0.4): + /@typescript-eslint/eslint-plugin@2.34.0(@typescript-eslint/parser@2.34.0)(eslint@6.8.0)(typescript@5.3.3): resolution: {integrity: sha512-4zY3Z88rEE99+CNvTbXSyovv2z9PNOVffTWD2W8QF5s2prBQtwN2zadqERcrHpcR7O/+KMI3fcTAmUUhK/iQcQ==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} peerDependencies: @@ -1956,25 +1956,25 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/experimental-utils': 2.34.0(eslint@6.8.0)(typescript@5.0.4) - '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.0.4) + '@typescript-eslint/experimental-utils': 2.34.0(eslint@6.8.0)(typescript@5.3.3) + '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.3.3) eslint: 6.8.0 functional-red-black-tree: 1.0.1 regexpp: 3.2.0 - tsutils: 3.21.0(typescript@5.0.4) - typescript: 5.0.4 + tsutils: 3.21.0(typescript@5.3.3) + typescript: 5.3.3 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/experimental-utils@2.34.0(eslint@6.8.0)(typescript@5.0.4): + /@typescript-eslint/experimental-utils@2.34.0(eslint@6.8.0)(typescript@5.3.3): resolution: {integrity: sha512-eS6FTkq+wuMJ+sgtuNTtcqavWXqsflWcfBnlYhg/nS4aZ1leewkXGbvBhaapn1q6qf4M71bsR1tez5JTRMuqwA==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} peerDependencies: eslint: '*' dependencies: '@types/json-schema': 7.0.11 - '@typescript-eslint/typescript-estree': 2.34.0(typescript@5.0.4) + '@typescript-eslint/typescript-estree': 2.34.0(typescript@5.3.3) eslint: 6.8.0 eslint-scope: 5.1.1 eslint-utils: 2.1.0 @@ -1983,7 +1983,7 @@ packages: - typescript dev: true - /@typescript-eslint/parser@2.34.0(eslint@6.8.0)(typescript@5.0.4): + /@typescript-eslint/parser@2.34.0(eslint@6.8.0)(typescript@5.3.3): resolution: {integrity: sha512-03ilO0ucSD0EPTw2X4PntSIRFtDPWjrVq7C3/Z3VQHRC7+13YB55rcJI3Jt+YgeHbjUdJPcPa7b23rXCBokuyA==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} peerDependencies: @@ -1994,16 +1994,16 @@ packages: optional: true dependencies: '@types/eslint-visitor-keys': 1.0.0 - '@typescript-eslint/experimental-utils': 2.34.0(eslint@6.8.0)(typescript@5.0.4) - '@typescript-eslint/typescript-estree': 2.34.0(typescript@5.0.4) + '@typescript-eslint/experimental-utils': 2.34.0(eslint@6.8.0)(typescript@5.3.3) + '@typescript-eslint/typescript-estree': 2.34.0(typescript@5.3.3) eslint: 6.8.0 eslint-visitor-keys: 1.3.0 - typescript: 5.0.4 + typescript: 5.3.3 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/typescript-estree@2.34.0(typescript@5.0.4): + /@typescript-eslint/typescript-estree@2.34.0(typescript@5.3.3): resolution: {integrity: sha512-OMAr+nJWKdlVM9LOqCqh3pQQPwxHAN7Du8DR6dmwCrAmxtiXQnhHJ6tBNtf+cggqfo51SG/FCwnKhXCIM7hnVg==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} peerDependencies: @@ -2018,8 +2018,8 @@ packages: is-glob: 4.0.3 lodash: 4.17.21 semver: 7.5.0 - tsutils: 3.21.0(typescript@5.0.4) - typescript: 5.0.4 + tsutils: 3.21.0(typescript@5.3.3) + typescript: 5.3.3 transitivePeerDependencies: - supports-color dev: true @@ -3230,8 +3230,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/eslint-plugin': 2.34.0(@typescript-eslint/parser@2.34.0)(eslint@6.8.0)(typescript@5.0.4) - '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.0.4) + '@typescript-eslint/eslint-plugin': 2.34.0(@typescript-eslint/parser@2.34.0)(eslint@6.8.0)(typescript@5.3.3) + '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.3.3) babel-eslint: 10.1.0(eslint@6.8.0) confusing-browser-globals: 1.0.11 eslint: 6.8.0 @@ -3274,7 +3274,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.0.4) + '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.3.3) debug: 3.2.7 eslint: 6.8.0 eslint-import-resolver-node: 0.3.7 @@ -3302,7 +3302,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.0.4) + '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.3.3) array-includes: 3.1.6 array.prototype.flat: 1.3.1 array.prototype.flatmap: 1.3.1 @@ -6937,8 +6937,8 @@ packages: '@rollup/plugin-node-resolve': 9.0.0(rollup@1.32.1) '@rollup/plugin-replace': 2.4.2(rollup@1.32.1) '@types/jest': 25.2.3 - '@typescript-eslint/eslint-plugin': 2.34.0(@typescript-eslint/parser@2.34.0)(eslint@6.8.0)(typescript@5.0.4) - '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.0.4) + '@typescript-eslint/eslint-plugin': 2.34.0(@typescript-eslint/parser@2.34.0)(eslint@6.8.0)(typescript@5.3.3) + '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@5.3.3) ansi-escapes: 4.3.2 asyncro: 3.0.0 babel-eslint: 10.1.0(eslint@6.8.0) @@ -7004,14 +7004,14 @@ packages: resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==} dev: true - /tsutils@3.21.0(typescript@5.0.4): + /tsutils@3.21.0(typescript@5.3.3): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} peerDependencies: typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' dependencies: tslib: 1.14.1 - typescript: 5.0.4 + typescript: 5.3.3 dev: true /tunnel-agent@0.6.0: @@ -7071,9 +7071,9 @@ packages: hasBin: true dev: true - /typescript@5.0.4: - resolution: {integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==} - engines: {node: '>=12.20'} + /typescript@5.3.3: + resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} + engines: {node: '>=14.17'} hasBin: true dev: true diff --git a/src/Activity.tsx b/src/Activity.tsx index 90e0f2d..2a3717d 100644 --- a/src/Activity.tsx +++ b/src/Activity.tsx @@ -1,9 +1,11 @@ import React, { Suspense } from "react"; import { Repeater } from "./Repeater"; +import { canUseDOM } from './canUseDOM'; import type { FC, ExoticComponent } from "react"; import type { IProps } from "./type"; const isSupportStableActivity = "Activity" in React; +const isBrowser = canUseDOM(); const NativeActivity = ( isSupportStableActivity @@ -16,7 +18,7 @@ const NativeActivity = ( ); -if(isSupportStableActivity) { +if(isBrowser && isSupportStableActivity) { console.warn( navigator.language === "zh-CN" ? '检测到您使用的react已经原生支持了Activity,我们 建议您迁移至原生Activity。' diff --git a/src/Repeater.tsx b/src/Repeater.tsx index 6edb46e..cd72064 100644 --- a/src/Repeater.tsx +++ b/src/Repeater.tsx @@ -1,7 +1,10 @@ import React, { useRef, useEffect } from "react"; +import { canUseDOM } from "./canUseDOM"; import type { FC } from "react"; import type { IProps } from "./type"; +const isBrowser = canUseDOM(); + export const Repeater: FC = (props) => { // props const { mode, children } = props; @@ -41,7 +44,7 @@ export const Repeater: FC = (props) => { // warning // ? throw a new promise is pending - if (mode === "hidden") { + if (isBrowser && mode === "hidden") { console.error( navigator.language === "zh-CN" ? ` diff --git a/src/canUseDOM.ts b/src/canUseDOM.ts new file mode 100644 index 0000000..5e9748f --- /dev/null +++ b/src/canUseDOM.ts @@ -0,0 +1,6 @@ +export const canUseDOM = () => + !!( + typeof window !== 'undefined' && + typeof window.document !== 'undefined' && + typeof window.document.createElement !== 'undefined' + );