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

Sync with react.dev @ b9eea4da #476

Merged
merged 2 commits into from
Jul 24, 2023
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
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"plugins": ["@typescript-eslint"],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn"
"@typescript-eslint/no-unused-vars": ["error", { "varsIgnorePattern": "^_" }],
"react-hooks/exhaustive-deps": "error"
},
"env": {
"node": true,
Expand Down
32 changes: 12 additions & 20 deletions src/components/Layout/HomeContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import {
useState,
useContext,
useId,
Fragment,
Suspense,
useEffect,
useRef,
useTransition,
useReducer,
} from 'react';
import cn from 'classnames';
import NextLink from 'next/link';
Expand All @@ -26,7 +24,6 @@ import {IconSearch} from 'components/Icon/IconSearch';
import {Logo} from 'components/Logo';
import Link from 'components/MDX/Link';
import CodeBlock from 'components/MDX/CodeBlock';
import {IconNavArrow} from 'components/Icon/IconNavArrow';
import {ExternalLink} from 'components/ExternalLink';
import sidebarBlog from '../../sidebarBlog.json';

Expand Down Expand Up @@ -67,14 +64,6 @@ function Para({children}) {
);
}

function Left({children}) {
return (
<div className="px-5 lg:px-0 max-w-4xl lg:text-left text-white text-opacity-80">
{children}
</div>
);
}

function Center({children}) {
return (
<div className="px-5 lg:px-0 max-w-4xl lg:text-center text-white text-opacity-80 flex flex-col items-center justify-center">
Expand All @@ -90,19 +79,23 @@ function FullBleed({children}) {
}

function CurrentTime() {
const msPerMinute = 60 * 1000;
const date = new Date();
let nextMinute = Math.floor(+date / msPerMinute + 1) * msPerMinute;

const [date, setDate] = useState(new Date());
const currentTime = date.toLocaleTimeString([], {
hour: 'numeric',
minute: 'numeric',
});
let [, forceUpdate] = useReducer((n) => n + 1, 0);
useEffect(() => {
const timeout = setTimeout(forceUpdate, nextMinute - Date.now());
const msPerMinute = 60 * 1000;
let nextMinute = Math.floor(+date / msPerMinute + 1) * msPerMinute;

const timeout = setTimeout(() => {
if (Date.now() > nextMinute) {
setDate(new Date());
}
}, nextMinute - Date.now());
return () => clearTimeout(timeout);
}, [date]);

return <span suppressHydrationWarning>{currentTime}</span>;
}

Expand Down Expand Up @@ -836,7 +829,7 @@ function ExampleLayout({
.filter((s) => s !== null);
setOverlayStyles(nextOverlayStyles);
}
}, [activeArea]);
}, [activeArea, hoverTopOffset]);
return (
<div className="lg:pl-10 lg:pr-5 w-full">
<div className="mt-12 mb-2 lg:my-16 max-w-7xl mx-auto flex flex-col w-full lg:rounded-2xl lg:bg-card lg:dark:bg-card-dark">
Expand Down Expand Up @@ -1216,7 +1209,7 @@ function useNestedScrollLock(ref) {
window.removeEventListener('scroll', handleScroll);
clearInterval(interval);
};
}, []);
}, [ref]);
}

function ExamplePanel({
Expand All @@ -1225,7 +1218,6 @@ function ExamplePanel({
noShadow,
height,
contentMarginTop,
activeArea,
}) {
return (
<div
Expand Down
1 change: 1 addition & 0 deletions src/components/Layout/Sidebar/SidebarLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function SidebarLink({
ref={ref}
title={title}
target={target}
passHref
aria-current={selected ? 'page' : undefined}
className={cn(
'p-2 pr-2 w-full rounded-none lg:rounded-r-2xl text-left hover:bg-gray-5 dark:hover:bg-gray-80 relative flex items-center justify-between',
Expand Down
1 change: 0 additions & 1 deletion src/components/Layout/SidebarNav/SidebarNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import {Suspense} from 'react';
import * as React from 'react';
import cn from 'classnames';
import {Search} from 'components/Search';
import {Feedback} from '../Feedback';
import {SidebarRouteTree} from '../Sidebar/SidebarRouteTree';
import type {RouteItem} from '../getRouteMeta';
Expand Down
3 changes: 1 addition & 2 deletions src/components/Layout/TopNav/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import {IconSearch} from 'components/Icon/IconSearch';
import {Search} from 'components/Search';
import {Logo} from '../../Logo';
import {Feedback} from '../Feedback';
import {SidebarRouteTree} from '../Sidebar/SidebarRouteTree';
import {SidebarRouteTree} from '../Sidebar';
import type {RouteItem} from '../getRouteMeta';
import {SidebarLink} from '../Sidebar';

declare global {
interface Window {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout/getRouteMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function getRouteMeta(cleanedPath: string, routeTree: RouteItem) {
currentIndex: 0,
};
buildRouteMeta(cleanedPath, routeTree, ctx);
const {currentIndex, ...meta} = ctx;
const {currentIndex: _, ...meta} = ctx;
return {
...meta,
breadcrumbs: breadcrumbs.length > 0 ? breadcrumbs : [routeTree],
Expand Down
1 change: 1 addition & 0 deletions src/components/MDX/BlogCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function BlogCard({title, badge, date, icon, url, children}: BlogCardProps) {
return (
<Link
href={url as string}
passHref
className="block h-full w-full rounded-2xl outline-none focus:outline-none focus-visible:outline focus-visible:outline-link focus:outline-offset-2 focus-visible:dark:focus:outline-link-dark">
<div className="justify-between p-5 sm:p-5 cursor-pointer w-full h-full flex flex-col flex-1 shadow-secondary-button-stroke dark:shadow-secondary-button-stroke-dark hover:bg-gray-40/5 active:bg-gray-40/10 hover:dark:bg-gray-60/5 active:dark:bg-gray-60/10 rounded-2xl text-xl text-primary dark:text-primary-dark leading-relaxed">
<div className="flex flex-row gap-3 w-full">
Expand Down
3 changes: 2 additions & 1 deletion src/components/MDX/MDXComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ function YouTubeIframe(props: any) {
}

function Image(props: any) {
return <img className="max-w-[calc(min(700px,100%))]" {...props} />;
const {alt, ...rest} = props;
return <img alt={alt} className="max-w-[calc(min(700px,100%))]" {...rest} />;
}

export const MDXComponents = {
Expand Down
1 change: 0 additions & 1 deletion src/components/MDX/Sandpack/CustomPreset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const CustomPreset = memo(function CustomPreset({

const SandboxShell = memo(function SandboxShell({
showDevTools,
onDevToolsLoad,
devToolsLoaded,
providedFiles,
lintErrors,
Expand Down
8 changes: 5 additions & 3 deletions src/components/MDX/Sandpack/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,17 @@ export function NavigationBar({providedFiles}: {providedFiles: Array<string>}) {
} else {
return;
}
}, [isMultiFile]);

// Note: in a real useEvent, onContainerResize would be omitted.
}, [isMultiFile, onContainerResize]);

const handleReset = () => {
/**
* resetAllFiles must come first, otherwise
* the previous content will appears for a second
* the previous content will appear for a second
* when the iframe loads.
*
* Plus, it should only prompts if there's any file changes
* Plus, it should only prompt if there's any file changes
*/
if (
sandpack.editorState === 'dirty' &&
Expand Down
1 change: 0 additions & 1 deletion src/components/MDX/Sandpack/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export function Preview({
errorScreenRegisteredRef,
openInCSBRegisteredRef,
loadingScreenRegisteredRef,
status,
} = sandpack;

if (
Expand Down
1 change: 0 additions & 1 deletion src/components/MDX/TeamMember.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Image from 'next/image';
import {IconTwitter} from '../Icon/IconTwitter';
import {IconGitHub} from '../Icon/IconGitHub';
import {ExternalLink} from '../ExternalLink';
import {IconNewPage} from 'components/Icon/IconNewPage';
import {H3} from './Heading';
import {IconLink} from 'components/Icon/IconLink';

Expand Down
3 changes: 1 addition & 2 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import Head from 'next/head';
import Link from 'next/link';
import Router from 'next/router';
import {lazy, useCallback, useEffect} from 'react';
import {lazy, useEffect} from 'react';
import * as React from 'react';
import {createPortal} from 'react-dom';
import {siteConfig} from 'siteConfig';
import cn from 'classnames';

export interface SearchProps {
appId?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePendingRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const usePendingRoute = () => {
events.off('routeChangeComplete', handleRouteChangeComplete);
clearTimeout(routeTransitionTimer);
};
}, []);
}, [events]);

return pendingRoute;
};
Expand Down
Loading