Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make sure that the package can be imported normally in ssr #544

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/_common
8 changes: 0 additions & 8 deletions src/_util/canUseDom.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/_util/renderToContainer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createPortal } from 'react-dom';
import { ReactElement, ReactPortal } from 'react';
import { resolveContainer } from './getContainer';
import { canUseDom } from './canUseDom';
import { canUseDocument } from './dom';

export type GetContainer = HTMLElement | (() => HTMLElement) | null;

export function renderToContainer(getContainer: GetContainer, node: ReactElement) {
if (canUseDom && getContainer) {
if (canUseDocument && getContainer) {
const container = resolveContainer(getContainer);
return createPortal(node, container as Element) as ReactPortal;
}
Expand Down
4 changes: 2 additions & 2 deletions src/_util/supportsPassive.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { canUseDom } from './canUseDom';
import { canUseDocument } from './dom';

// eslint-disable-next-line
export let supportsPassive = false;

if (canUseDom) {
if (canUseDocument) {
try {
const opts = {};
Object.defineProperty(opts, 'passive', {
Expand Down
4 changes: 2 additions & 2 deletions src/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { FC } from 'react';
import React, { useContext } from 'react';
import cls from 'classnames';
import Image from 'tdesign-mobile-react/image';
import Badge from 'tdesign-mobile-react/badge';
import Image from '../image';
import Badge from '../badge';
import { AvatarGroupContext } from './AvatarGroupContext';
import { isValidSize } from '../_common/js/avatar/utils';
import parseTNode from '../_util/parseTNode';
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useLayoutEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useLayoutEffect, useEffect } from 'react';
import { canUseDocument } from '../_util/dom';

const useIsomorphicLayoutEffect = canUseDocument ? useLayoutEffect : useEffect;

export default useIsomorphicLayoutEffect;
3 changes: 2 additions & 1 deletion src/loading/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { StyledProps } from '../common';
import Spinner from './icon/Spinner';
import Gradient from './icon/Gradient';
import Portal from '../common/Portal';
import { canUseDocument } from '../_util/dom';
import { useLockScroll } from '../hooks/useLockScroll';
import useDefaultProps from '../hooks/useDefaultProps';
import { usePrefixClass } from '../hooks/useClass';
Expand Down Expand Up @@ -43,7 +44,7 @@ const Loading: React.FC<LoadingProps> = (props) => {
const fullClass = `${loadingClass}--full`;
const relativeClass = `${loadingClass}__parent`;

useLockScroll(loadingRef, loading && fullscreen && preventScrollThrough, loadingClass);
useLockScroll(loadingRef, canUseDocument && loading && fullscreen && preventScrollThrough, loadingClass);

// 当延时加载delay有值时,值会发生变化
const [reloading, setReloading] = useState(!delay && loading);
Expand Down
3 changes: 2 additions & 1 deletion src/sticky/Sticky.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { FC, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
import React, { FC, useCallback, useEffect, useRef, useState } from 'react';
import useConfig from '../_util/useConfig';
import { TdStickyProps } from './type';
import { stickyDefaultProps } from './defaultProps';
import { resolveContainer } from '../_util/getContainer';
import useDefaultProps from '../hooks/useDefaultProps';
import useLayoutEffect from '../hooks/useLayoutEffect';

const Sticky: FC<TdStickyProps> = (originProps) => {
const props = useDefaultProps(originProps, stickyDefaultProps);
Expand Down
3 changes: 2 additions & 1 deletion src/swipe-cell/SwipeCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useImperativeHandle, useRef, useLayoutEffect, useMemo, useState } from 'react';
import React, { forwardRef, useImperativeHandle, useRef, useMemo, useState } from 'react';
import type { ReactNode } from 'react';
import isArray from 'lodash/isArray';
import isBoolean from 'lodash/isBoolean';
Expand All @@ -12,6 +12,7 @@ import { TdSwipeCellProps, SwipeActionItem, Sure } from './type';
import { swipeCellDefaultProps } from './defaultProps';
import { usePrefixClass } from '../hooks/useClass';
import useDefaultProps from '../hooks/useDefaultProps';
import useLayoutEffect from '../hooks/useLayoutEffect';
import { Styles, StyledProps } from '../common';

import './style';
Expand Down
Loading