-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: fix Previewer component under color scheme change with iframe key #2301
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,15 +1,23 @@ | ||||||
| import { ReactComponent as IconError } from '@ant-design/icons-svg/inline-svg/filled/close-circle.svg'; | ||||||
| import classnames from 'classnames'; | ||||||
| import { useLiveDemo, useLocation, type IPreviewerProps } from 'dumi'; | ||||||
| import { | ||||||
| useLiveDemo, | ||||||
| useLocation, | ||||||
| usePrefersColor, | ||||||
| type IPreviewerProps, | ||||||
| } from 'dumi'; | ||||||
| import PreviewerActions from 'dumi/theme/slots/PreviewerActions'; | ||||||
| import React, { useRef, type FC } from 'react'; | ||||||
| import React, { useEffect, useRef, useState, type FC } from 'react'; | ||||||
| import './index.less'; | ||||||
|
|
||||||
| const Previewer: FC<IPreviewerProps> = (props) => { | ||||||
| const demoContainer = useRef<HTMLDivElement>(null); | ||||||
| const { hash } = useLocation(); | ||||||
| const link = `#${props.asset.id}`; | ||||||
|
|
||||||
| const [preferredColorScheme] = usePrefersColor(); | ||||||
| const [iframeKey, setIframeKey] = useState(0); | ||||||
|
|
||||||
| const { | ||||||
| node: liveDemoNode, | ||||||
| error: liveDemoError, | ||||||
|
|
@@ -20,6 +28,12 @@ const Previewer: FC<IPreviewerProps> = (props) => { | |||||
| containerRef: demoContainer, | ||||||
| }); | ||||||
|
|
||||||
| useEffect(() => { | ||||||
| if (props.iframe) { | ||||||
| setIframeKey((key) => key + 1); | ||||||
| } | ||||||
| }, [preferredColorScheme, props.iframe]); | ||||||
|
||||||
| }, [preferredColorScheme, props.iframe]); | |
| }, [preferredColorScheme]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iframe参数也可以设置为demo的高度,我的理解是这个参数变化应该也要更新demo块吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name
preferredColorSchemeis misleading. The first value returned byusePrefersColor()is the resolved color ('light' or 'dark'), not the preferred color scheme (which can be 'auto', 'light', or 'dark').Consider renaming to
colororcolorSchemeto match the convention used in the hook's implementation and to be more accurate about what it represents.Example: