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

[pull] main from nodejs:main #308

Merged
merged 2 commits into from
Nov 11, 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 components/Common/ActiveLocalizedLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import classNames from 'classnames';
import type { ComponentProps, FC } from 'react';

import { Link, usePathname } from '@/navigation.mjs';
import Link from '@/components/Link';
import { usePathname } from '@/navigation.mjs';

type ActiveLocalizedLinkProps = ComponentProps<typeof Link> & {
activeClassName: string;
Expand Down
2 changes: 1 addition & 1 deletion components/Common/Badge/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ArrowRightIcon from '@heroicons/react/24/solid/ArrowRightIcon';
import type { ComponentProps, FC, PropsWithChildren } from 'react';

import { Link } from '@/navigation.mjs';
import Link from '@/components/Link';

import styles from './index.module.css';

Expand Down
2 changes: 1 addition & 1 deletion components/Common/Banner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ArrowUpRightIcon } from '@heroicons/react/24/outline';
import type { FC } from 'react';

import { Link } from '@/navigation.mjs';
import Link from '@/components/Link';

import styles from './index.module.css';

Expand Down
2 changes: 1 addition & 1 deletion components/Common/Breadcrumbs/BreadcrumbLink/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import type { ComponentProps, FC } from 'react';

import { Link } from '@/navigation.mjs';
import Link from '@/components/Link';

import styles from './index.module.css';

Expand Down
2 changes: 1 addition & 1 deletion components/Common/CrossLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslations } from 'next-intl';
import type { FC } from 'react';

import PrevNextArrow from '@/components/Common/PrevNextArrow';
import { Link } from '@/navigation.mjs';
import Link from '@/components/Link';

import styles from './index.module.css';

Expand Down
2 changes: 1 addition & 1 deletion components/Common/MetaBar/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Image from 'next/image';

import AvatarGroup from '@/components/Common/AvatarGroup';
import MetaBar from '@/components/Common/MetaBar';
import { Link } from '@/navigation.mjs';
import Link from '@/components/Link';

type Story = StoryObj<typeof MetaBar>;
type Meta = MetaObj<typeof MetaBar>;
Expand Down
2 changes: 1 addition & 1 deletion components/Common/MetaBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslations } from 'next-intl';
import { Fragment, useMemo } from 'react';
import type { FC } from 'react';

import { Link } from '@/navigation.mjs';
import Link from '@/components/Link';

import styles from './index.module.css';

Expand Down
2 changes: 1 addition & 1 deletion components/Common/Pagination/PaginationListItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslations } from 'next-intl';
import type { FC } from 'react';

import { Link } from '@/navigation.mjs';
import Link from '@/components/Link';

import styles from './index.module.css';

Expand Down
2 changes: 1 addition & 1 deletion components/Downloads/DownloadList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useTranslations } from 'next-intl';
import type { FC } from 'react';

import Link from '@/components/Link';
import { useSiteNavigation } from '@/hooks/server';
import { Link } from '@/navigation.mjs';
import type { NodeRelease } from '@/types';

const DownloadList: FC<NodeRelease> = ({ versionWithPrefix }) => {
Expand Down
2 changes: 1 addition & 1 deletion components/Downloads/PrimaryDownloadMatrix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import classNames from 'classnames';
import type { FC } from 'react';
import semVer from 'semver';

import Link from '@/components/Link';
import { WithCurrentOS } from '@/components/withCurrentOS';
import { useClientContext } from '@/hooks';
import { Link } from '@/navigation.mjs';
import { DIST_URL } from '@/next.constants.mjs';
import type { NodeRelease } from '@/types';

Expand Down
2 changes: 1 addition & 1 deletion components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FC } from 'react';

import { Link } from '@/navigation.mjs';
import Link from '@/components/Link';

type FooterProps = { className?: string };

Expand Down
3 changes: 2 additions & 1 deletion components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { useTranslations } from 'next-intl';
import { useTheme } from 'next-themes';
import { useState } from 'react';

import Link from '@/components/Link';
import { useIsCurrentPathname, useSiteNavigation } from '@/hooks';
import { Link, usePathname } from '@/navigation.mjs';
import { usePathname } from '@/navigation.mjs';
import { BASE_PATH } from '@/next.constants.mjs';
import { availableLocales } from '@/next.locales.mjs';

Expand Down
2 changes: 1 addition & 1 deletion components/Home/HomeDownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { useTranslations } from 'next-intl';
import type { FC } from 'react';

import Link from '@/components/Link';
import { useDetectOS } from '@/hooks';
import { Link } from '@/navigation.mjs';
import { DIST_URL } from '@/next.constants.mjs';
import type { NodeRelease } from '@/types';
import { downloadUrlByOS } from '@/util/downloadUrlByOS';
Expand Down
31 changes: 31 additions & 0 deletions components/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useMemo } from 'react';
import type { FC, ComponentProps, HTMLAttributes as Attributes } from 'react';

import { Link as LocalizedLink } from '@/navigation.mjs';

// This is a wrapper on HTML's `a` tag
const Html: FC<Attributes<HTMLAnchorElement>> = ({ children, ...p }) => (
<a {...p}>{children}</a>
);

// This is Next.js's Link Component but with pre-fetch disabled
const Next: FC<ComponentProps<typeof Link>> = ({ children, ...p }) => (
<LocalizedLink {...p}>{children}</LocalizedLink>
);

const Link: FC<ComponentProps<typeof LocalizedLink>> = ({
children,
...props
}) => {
const Component = useMemo(
// Uses a different Link element/tag based on the nature of the Link
// as we don't want prefetch/rsc or etc for external links
() =>
!props.href || props.href.toString().startsWith('http') ? Html : Next,
[props.href]
);

return <Component {...props}>{children}</Component>;
};

export default Link;
2 changes: 1 addition & 1 deletion components/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslations } from 'next-intl';
import type { FC } from 'react';

import { Link } from '@/navigation.mjs';
import Link from '@/components/Link';

type PaginationProps = { prev?: number; next?: number };

Expand Down
2 changes: 1 addition & 1 deletion components/SideNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import classNames from 'classnames';
import type { RichTranslationValues } from 'next-intl';
import type { FC } from 'react';

import Link from '@/components/Link';
import { useIsCurrentPathname, useSiteNavigation } from '@/hooks';
import { Link } from '@/navigation.mjs';
import type { NavigationKeys } from '@/types';

type SideNavigationProps = {
Expand Down
2 changes: 1 addition & 1 deletion layouts/BlogCategoryLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useMemo } from 'react';
import type { FC } from 'react';

import { Time } from '@/components/Common/Time';
import Link from '@/components/Link';
import Pagination from '@/components/Pagination';
import { useClientContext, useBlogData } from '@/hooks/server';
import { Link } from '@/navigation.mjs';
import type { BlogPost } from '@/types';

const BlogCategoryLayout: FC = () => {
Expand Down
2 changes: 1 addition & 1 deletion next.mdx.use.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import NodeApiVersionLinks from './components/Docs/NodeApiVersionLinks';
import DownloadReleasesTable from './components/Downloads/DownloadReleasesTable';
import Banner from './components/Home/Banner';
import HomeDownloadButton from './components/Home/HomeDownloadButton';
import Link from './components/Link';
import { WithNodeRelease } from './components/withNodeRelease';
import { Link } from './navigation.mjs';

/**
* A full list of React Components that we want to passthrough to MDX
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
"@testing-library/react": "~14.0.0",
"@testing-library/user-event": "~14.5.1",
"@types/jest": "29.5.7",
"@types/react": "^18.2.24",
"@types/react-dom": "^18.2.9",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@types/semver": "~7.5.5",
"@typescript-eslint/eslint-plugin": "6.9.0",
"@typescript-eslint/parser": "6.9.0",
Expand Down
Loading