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

fix(Guide): fix guide initial position in ssr #2832

Merged
merged 2 commits into from
Apr 7, 2024
Merged
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
16 changes: 11 additions & 5 deletions src/guide/Guide.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import React, { useMemo, useEffect, useRef, useState } from 'react';
import isFunction from 'lodash/isFunction';
import cx from 'classnames';
import { createPortal } from 'react-dom';
Expand All @@ -12,6 +12,7 @@ import setStyle from '../_common/js/utils/set-style';
import useControlled from '../hooks/useControlled';
import { guideDefaultProps } from './defaultProps';
import useDefaultProps from '../hooks/useDefaultProps';
import useIsomorphicLayoutEffect from '../_util/useLayoutEffect';

export type GuideProps = TdGuideProps;

Expand Down Expand Up @@ -88,7 +89,6 @@ const Guide: React.FC<GuideProps> = (originalProps) => {

const showPopupGuide = () => {
currentHighlightLayerElm.current = getTargetElm(currentStepInfo.element);

setTimeout(() => {
scrollToParentVisibleArea(currentHighlightLayerElm.current);
setHighlightLayerPosition(highlightLayerRef.current);
Expand All @@ -104,6 +104,7 @@ const Guide: React.FC<GuideProps> = (originalProps) => {
const showDialogGuide = () => {
setTimeout(() => {
currentHighlightLayerElm.current = dialogTooltipRef.current;

scrollToParentVisibleArea(currentHighlightLayerElm.current);
setHighlightLayerPosition(highlightLayerRef.current);
scrollToElm(currentHighlightLayerElm.current);
Expand Down Expand Up @@ -179,7 +180,7 @@ const Guide: React.FC<GuideProps> = (originalProps) => {
}
};

useEffect(() => {
useIsomorphicLayoutEffect(() => {
if (innerCurrent >= 0 && innerCurrent < steps.length) {
initGuide();
} else {
Expand All @@ -189,13 +190,18 @@ const Guide: React.FC<GuideProps> = (originalProps) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [innerCurrent]);

useEffect(() => {
useIsomorphicLayoutEffect(() => {
initGuide();

return destroyGuide;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(
() => destroyGuide,
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);

const renderOverlayLayer = () =>
createPortal(
<div ref={overlayLayerRef} className={`${prefixCls}__overlay`} style={{ zIndex: zIndex - 2 }} />,
Expand Down
Loading