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

feat(devtools/doctor): improved setup guide #5415

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
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ export const ErrorFallback: React.FC<ErrorFallbackProps> = props => {
<Heading as="h4" mb="4">
<Text as="span">{title}</Text>
</Heading>
<TextArea disabled style={{ height: '50vh' }}>
{description}
</TextArea>
<TextArea disabled style={{ height: '50vh' }} value={description} />
</Box>
);
};

export const ErrorRouteHandler: React.FC<ErrorFallbackProps> = props => {
export const ErrorRouteHandler: React.FC = () => {
const error = useRouteError();
return <ErrorFallback {...props} error={error} />;
return <ErrorFallback resetErrorBoundary={() => null} error={error} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.container {
width: max-content;
min-width: var(--space-9);
color: var(--gray-11);
}

.children {
color: var(--gray-9);
}
25 changes: 25 additions & 0 deletions packages/devtools/client/src/components/Error/FeatureDisabled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { PropsWithChildren } from 'react';
import { Box, Flex, Heading } from '@radix-ui/themes';
import { HiExclamationCircle } from 'react-icons/hi2';
import styles from './FeatureDisabled.module.scss';

export interface FeatureDisabledProps extends PropsWithChildren {
title: string;
}

export const FeatureDisabled: React.FC<FeatureDisabledProps> = props => {
const { title, children } = props;
return (
<Flex className={styles.container} mt="9" mx="auto" gap="2">
<Flex height="9" align="center">
<HiExclamationCircle size="36" />
</Flex>
<Box>
<Flex height="9" align="center">
<Heading>{title}</Heading>
</Flex>
<Box className={styles.children}>{children}</Box>
</Box>
</Flex>
);
};
Empty file.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ErrorRouteHandler } from '@/components/ErrorFallback/ErrorFallback';
import { ErrorRouteHandler } from '@/components/Error/Fallback';

export default ErrorRouteHandler;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ErrorRouteHandler } from '@/components/ErrorFallback/ErrorFallback';
import { ErrorRouteHandler } from '@/components/Error/Fallback';

export default ErrorRouteHandler;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { FC } from 'react';
import { useRouteError } from '@modern-js/runtime/router';
import { Box, Link } from '@radix-ui/themes';
import { useSnapshot } from 'valtio';
import { parseURL } from 'ufo';
import { $definition } from '../state';
import {
ErrorFallbackProps,
ErrorRouteHandler,
} from '@/components/Error/Fallback';
import { FeatureDisabled } from '@/components/Error/FeatureDisabled';

const Handler: FC<ErrorFallbackProps> = () => {
const error = useRouteError();
const def = useSnapshot($definition);
const isStateError =
error && typeof error === 'object' && Object.keys(error).length === 0;
if (isStateError) {
const websiteDisplay = parseURL(def.doctor.website).host;
const websiteLink = (
<Link href={def.doctor.website} target="_blank" rel="noopener noreferrer">
🔗{websiteDisplay}
</Link>
);
return (
<Box width="100%">
<FeatureDisabled title="Doctor is not working">
Visit the website of {websiteLink} to learn more.
</FeatureDisabled>
</Box>
);
} else {
return <ErrorRouteHandler />;
}
};

export default Handler;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import _ from 'lodash';
import { parseURL } from 'ufo';
import clsx from 'clsx';
import { $dependencies } from '../state';
import { $definition, $dependencies } from '../state';
import logo from './rsdoctor-large.png';
import { $doctor } from './state';
import styles from './page.module.scss';
Expand Down Expand Up @@ -79,11 +79,12 @@ const Page: FC = () => {
const doctor = useSnapshot($doctor);

const dependencies = useSnapshot($dependencies);
const def = useSnapshot($definition);
const isWebDoctor = Object.keys(dependencies).find(key =>
key.startsWith('@web-doctor/'),
);
const implementation = isWebDoctor ? 'Web Doctor' : 'Rsdoctor';
const website = 'https://rsdoctor.dev';
const { website } = def.doctor;
const version =
dependencies['@web-doctor/webpack-plugin(builder)'] ??
dependencies['@web-doctor/rspack-plugin(builder)'] ??
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ErrorRouteHandler } from '@/components/ErrorFallback/ErrorFallback';
import { ErrorRouteHandler } from '@/components/Error/Fallback';

export default ErrorRouteHandler;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ErrorRouteHandler } from '@/components/ErrorFallback/ErrorFallback';
import { ErrorRouteHandler } from '@/components/Error/Fallback';

export default ErrorRouteHandler;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ErrorRouteHandler } from '@/components/ErrorFallback/ErrorFallback';
import { ErrorRouteHandler } from '@/components/Error/Fallback';

export default ErrorRouteHandler;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ErrorRouteHandler } from '@/components/ErrorFallback/ErrorFallback';
import { ErrorRouteHandler } from '@/components/Error/Fallback';

export default ErrorRouteHandler;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ErrorRouteHandler } from '@/components/ErrorFallback/ErrorFallback';
import { ErrorRouteHandler } from '@/components/Error/Fallback';

export default ErrorRouteHandler;
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const $definition = proxy({
packages: _definitionTask.then(def => def.packages),
assets: _definitionTask.then(def => def.assets),
announcement: _definitionTask.then(def => def.announcement),
doctor: _definitionTask.then(def => def.doctor),
});

export const _dependenciesTask = $server.then(({ remote }) =>
Expand Down
6 changes: 6 additions & 0 deletions packages/devtools/kit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ export class AnnouncementDefinition {
fallback: string = 'https://modernjs.dev/';
}

export class DoctorDefinition {
website: string = 'https://rsdoctor.dev';
}

export class ClientDefinition {
name: NameDefinition = new NameDefinition();

packages: PackageDefinition = new PackageDefinition();

assets: AssetDefinition = new AssetDefinition();

doctor: DoctorDefinition = new DoctorDefinition();

announcement: AnnouncementDefinition = new AnnouncementDefinition();
}

Expand Down
9 changes: 6 additions & 3 deletions packages/devtools/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@
"jsnext:source": "./src/index.ts",
"require": "./dist/index.js"
},
"default": "./dist/index.js"
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./cli": {
"jsnext:source": "./src/cli.ts",
"default": "./dist/cli.js"
"default": "./dist/cli.js",
"types": "./dist/cli.d.ts"
},
"./runtime": {
"jsnext:source": "./src/runtime.ts",
"default": "./dist/runtime.js"
"default": "./dist/runtime.js",
"types": "./dist/runtime.d.ts"
}
},
"scripts": {
Expand Down
Loading
Loading