diff --git a/.changeset/wicked-toes-beg.md b/.changeset/wicked-toes-beg.md new file mode 100644 index 000000000000..19ffc7aff816 --- /dev/null +++ b/.changeset/wicked-toes-beg.md @@ -0,0 +1,9 @@ +--- +'@integration-test/devtools': minor +'@modern-js/devtools-client': minor +'@modern-js/plugin-devtools': minor +'@modern-js/devtools-kit': minor +--- + +feat(devtools): add new doctor tab to show overview of rsdoctor +feat(devtools): 新增 doctor 页面展示 Rsdoctor 概览信息 diff --git a/packages/devtools/client/modern.config.ts b/packages/devtools/client/modern.config.ts index e2459b0c811e..1b3ffc94d7d3 100644 --- a/packages/devtools/client/modern.config.ts +++ b/packages/devtools/client/modern.config.ts @@ -46,6 +46,22 @@ export default defineConfig<'rspack'>({ disableInlineRuntimeChunk: true, disableSourceMap: process.env.NODE_ENV === 'production', }, + performance: { + chunkSplit: { + strategy: 'split-by-experience', + override: { + cacheGroups: { + components: { + test: /\/src\/components\/.*\.(scss|css)$/, + chunks: 'all', + name: 'components', + enforce: true, + priority: 9999, + }, + }, + }, + }, + }, tools: { postcss: (config, { addPlugins }) => { addPlugins(require('postcss-custom-media')); diff --git a/packages/devtools/client/src/assets/NotoSans-latin-subset.woff2 b/packages/devtools/client/src/assets/NotoSans-latin-subset.woff2 new file mode 100644 index 000000000000..d2f454384d4d Binary files /dev/null and b/packages/devtools/client/src/assets/NotoSans-latin-subset.woff2 differ diff --git a/packages/devtools/client/src/components/Card/Indicate.module.scss b/packages/devtools/client/src/components/Card/Indicate.module.scss new file mode 100644 index 000000000000..08cfc156efd2 --- /dev/null +++ b/packages/devtools/client/src/components/Card/Indicate.module.scss @@ -0,0 +1,8 @@ +.indicate-card { + border-radius: var(--radius-5); + box-shadow: var(--shadow-4); + padding: var(--space-5); + :global(.dark) & { + background-color: var(--gray-1); + } +} diff --git a/packages/devtools/client/src/components/Card/Indicate.tsx b/packages/devtools/client/src/components/Card/Indicate.tsx new file mode 100644 index 000000000000..25be8691694d --- /dev/null +++ b/packages/devtools/client/src/components/Card/Indicate.tsx @@ -0,0 +1,35 @@ +import { FC } from 'react'; +import clsx from 'clsx'; +import { Box, Flex } from '@radix-ui/themes'; +import type { BoxProps } from '@radix-ui/themes/dist/cjs/components/box'; +import type { FlexProps } from '@radix-ui/themes/dist/cjs/components/flex'; +import styles from './Indicate.module.scss'; + +export type IndicateCardProps = BoxProps & React.RefAttributes; + +const Card: FC = ({ children, className, ...props }) => { + return ( + + {children} + + ); +}; + +Card.displayName = 'IndicateCard'; + +const Column: FC = props => ( + +); + +Column.displayName = 'IndicateCard.Column'; + +export const IndicateCard = Object.assign(Card, { + Column, +}); diff --git a/packages/devtools/client/src/components/Card/index.ts b/packages/devtools/client/src/components/Card/index.ts new file mode 100644 index 000000000000..65cde4cb5201 --- /dev/null +++ b/packages/devtools/client/src/components/Card/index.ts @@ -0,0 +1 @@ +export * from './Indicate'; diff --git a/packages/devtools/client/src/components/Devtools/Capsule.tsx b/packages/devtools/client/src/components/Devtools/Capsule.tsx index 50228cf8016f..3943bdc76a8e 100644 --- a/packages/devtools/client/src/components/Devtools/Capsule.tsx +++ b/packages/devtools/client/src/components/Devtools/Capsule.tsx @@ -1,7 +1,7 @@ import { SetupClientParams } from '@modern-js/devtools-kit/runtime'; import { Flex, Theme } from '@radix-ui/themes'; import React, { useEffect, useState } from 'react'; -import { useEvent, useToggle } from 'react-use'; +import { useAsync, useEvent, useToggle } from 'react-use'; import { HiMiniCursorArrowRipple } from 'react-icons/hi2'; import { withQuery } from 'ufo'; import Visible from '../Visible'; @@ -13,9 +13,21 @@ import { $client, wallAgent } from '@/entries/mount/state'; import { pTimeout } from '@/utils/promise'; import { ReactDevtoolsWallListener } from '@/utils/react-devtools'; +const parseDeepLink = (url = window.location) => { + // Expected: #/__devtools/doctor + const { hash } = url; + // Parse pathname from hash. + const pathname = hash.match(/^#\/__devtools(.*)/)?.[1]; + // Check if match the expected pattern. + if (typeof pathname !== 'string') return null; + if (pathname === '') return '/'; + return pathname; +}; + export const DevtoolsCapsule: React.FC = props => { const logoSrc = props.def.assets.logo; - const [showDevtools, toggleDevtools] = useToggle(false); + const deepLink = parseDeepLink(); + const [showDevtools, toggleDevtools] = useToggle(Boolean(deepLink)); const [loadDevtools, setLoadDevtools] = useState(false); const src = withQuery(props.endpoint, { src: props.dataSource }); @@ -64,13 +76,19 @@ export const DevtoolsCapsule: React.FC = props => { setLoadDevtools(true); try { const client = await pTimeout($client, 10_000); - client.remote.pullUpReactInspector(); + client.remote.pullUp('/react/components#inspecting'); } catch (e) { console.error(e); document.documentElement.style.removeProperty('cursor'); } }; + useAsync(async () => { + if (!deepLink) return; + const client = await pTimeout($client, 10_000); + client.remote.pullUp(deepLink); + }, []); + return ( diff --git a/packages/devtools/client/src/components/Devtools/Puller.tsx b/packages/devtools/client/src/components/Devtools/Puller.tsx index d3110cccb074..b105097740e2 100644 --- a/packages/devtools/client/src/components/Devtools/Puller.tsx +++ b/packages/devtools/client/src/components/Devtools/Puller.tsx @@ -2,32 +2,23 @@ import React, { useEffect } from 'react'; import { useNavigate } from '@modern-js/runtime/router'; import { useThrowable } from '@/utils'; import { $mountPoint } from '@/entries/client/routes/state'; -import { wallAgent } from '@/entries/client/routes/react/state'; -let _intendPullUp = false; +let _intendPullUp = ''; $mountPoint.then(({ hooks }) => { - hooks.hookOnce('pullUpReactInspector', async () => { - _intendPullUp = true; + hooks.hookOnce('pullUp', async target => { + _intendPullUp = target; }); }); -export const DevtoolsPuller: React.FC = () => { +export const Puller: React.FC = () => { const navigate = useNavigate(); const mountPoint = useThrowable($mountPoint); - const handlePullUp = async () => { - navigate('/react'); - if (wallAgent.status === 'active') { - wallAgent.send('startInspectingNative', null); - } else { - wallAgent.hookOnce('active', () => { - wallAgent.send('startInspectingNative', null); - }); - } - }; useEffect(() => { - _intendPullUp && handlePullUp(); - mountPoint.hooks.hook('pullUpReactInspector', handlePullUp); + _intendPullUp && navigate(_intendPullUp); + mountPoint.hooks.hook('pullUp', async target => { + navigate(target); + }); }, []); return null; }; diff --git a/packages/devtools/client/src/components/ErrorFallback/ErrorFallback.tsx b/packages/devtools/client/src/components/Error/Fallback.tsx similarity index 77% rename from packages/devtools/client/src/components/ErrorFallback/ErrorFallback.tsx rename to packages/devtools/client/src/components/Error/Fallback.tsx index f0356b35f15b..899cf53e7a89 100644 --- a/packages/devtools/client/src/components/ErrorFallback/ErrorFallback.tsx +++ b/packages/devtools/client/src/components/Error/Fallback.tsx @@ -21,14 +21,12 @@ export const ErrorFallback: React.FC = props => { {title} - +