Skip to content

Commit 06d12a6

Browse files
authored
site: inject runtime styles with useInsertionEffect (#59775)
* refactor(site): use useInsertionEffect for runtime CSS injection * update
1 parent a614024 commit 06d12a6

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎.dumi/hooks/useThemeAnimation.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useRef } from 'react';
1+
import { useEffect, useInsertionEffect, useRef } from 'react';
22
import { removeCSS, updateCSS } from '@rc-component/util';
33
import { theme } from 'antd';
44

@@ -105,7 +105,7 @@ const useThemeAnimation = () => {
105105
};
106106

107107
// inject transition style
108-
useEffect(() => {
108+
useInsertionEffect(() => {
109109
if (typeof document.startViewTransition === 'function') {
110110
updateCSS(viewTransitionStyle, 'view-transition-style');
111111
}

‎.dumi/theme/SiteThemeProvider.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const SiteThemeProvider: React.FC<ThemeProviderProps<any>> = ({ children, theme,
4141
ConfigProvider.config({ theme: theme as ThemeConfig });
4242
}, [theme]);
4343

44-
React.useEffect(() => {
44+
React.useInsertionEffect(() => {
4545
// iframe demo 生效
4646
if (window.parent !== window) {
4747
updateCSS(

‎.dumi/theme/builtins/Previewer/CodePreviewer.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useRef, useState } from 'react';
1+
import React, { useEffect, useInsertionEffect, useMemo, useRef, useState } from 'react';
22
import { UpOutlined } from '@ant-design/icons';
33
import type { MenuProps } from 'antd';
44
import { Badge, Tag, Tooltip } from 'antd';
@@ -286,7 +286,7 @@ const CodePreviewer: React.FC<AntdPreviewerProps> = (props) => {
286286
</section>
287287
);
288288

289-
useEffect(() => {
289+
useInsertionEffect(() => {
290290
// In Safari, if style tag be inserted into non-head tag,
291291
// it will affect the rendering ability of the browser,
292292
// resulting in some response delays like following issue:

0 commit comments

Comments
 (0)