Skip to content

Commit

Permalink
feat: server兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
IVLIU committed Mar 4, 2024
1 parent 2bfb934 commit 3a71216
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 36 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
],
"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",
"react-dom": "^18.2.0",
"size-limit": "^8.2.4",
"tsdx": "^0.14.1",
"tslib": "^2.5.0",
"typescript": "^5.0.4"
"typescript": "^5.3.3"
}
}
64 changes: 32 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/Activity.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +18,7 @@ const NativeActivity = (
);


if(isSupportStableActivity) {
if(isBrowser && isSupportStableActivity) {
console.warn(
navigator.language === "zh-CN"
? '检测到您使用的react已经原生支持了Activity,我们 建议您迁移至原生Activity。'
Expand Down
5 changes: 4 additions & 1 deletion src/Repeater.tsx
Original file line number Diff line number Diff line change
@@ -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<IProps> = (props) => {
// props
const { mode, children } = props;
Expand Down Expand Up @@ -41,7 +44,7 @@ export const Repeater: FC<IProps> = (props) => {

// warning
// ? throw a new promise is pending
if (mode === "hidden") {
if (isBrowser && mode === "hidden") {
console.error(
navigator.language === "zh-CN"
? `
Expand Down
6 changes: 6 additions & 0 deletions src/canUseDOM.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const canUseDOM = () =>
!!(
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined'
);

0 comments on commit 3a71216

Please sign in to comment.