Skip to content

Commit 722ff36

Browse files
authored
Merge pull request #12050 from ethereum/link-i18n
Fix i18n links not having the locale in hrefs
2 parents 08b181e + 120d0ba commit 722ff36

File tree

5 files changed

+12
-24
lines changed

5 files changed

+12
-24
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"markdown-checker": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/markdownChecker.ts"
2121
},
2222
"dependencies": {
23-
"@chakra-ui/next-js": "^2.1.5",
2423
"@chakra-ui/react": "^2.8.0",
2524
"@crowdin/crowdin-api-client": "^1.25.0",
2625
"@docsearch/react": "^3.5.2",

src/components/Link.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
import NextLink, { type LinkProps as NextLinkProps } from "next/link"
12
import { useRouter } from "next/router"
23
import { RxExternalLink } from "react-icons/rx"
3-
import {
4-
Link as NextLink,
5-
type LinkProps as NextLinkProps,
6-
} from "@chakra-ui/next-js"
74
import {
85
forwardRef,
96
Icon,
107
Link as ChakraLink,
8+
type LinkProps as ChakraLinkProps,
119
type StyleProps,
1210
VisuallyHidden,
1311
} from "@chakra-ui/react"
@@ -30,7 +28,9 @@ type BaseProps = {
3028
customEventOptions?: MatomoEventOptions
3129
}
3230

33-
export type LinkProps = BaseProps & Omit<NextLinkProps, "href">
31+
export type LinkProps = BaseProps &
32+
ChakraLinkProps &
33+
Omit<NextLinkProps, "as" | "legacyBehavior" | "passHref" | "href">
3434

3535
/**
3636
* Link wrapper which handles:
@@ -57,11 +57,11 @@ export const BaseLink = forwardRef(function Link(
5757
}: LinkProps,
5858
ref
5959
) {
60-
let href = (to ?? hrefProp) as string
61-
62-
const { asPath, locale } = useRouter()
60+
const { asPath } = useRouter()
6361
const { flipForRtl } = useRtlFlip()
6462

63+
let href = (to ?? hrefProp) as string
64+
6565
const isActive = url.isHrefActive(href, asPath, isPartiallyActive)
6666
const isDiscordInvite = url.isDiscordInvite(href)
6767
const isPdf = url.isPdf(href)
@@ -142,8 +142,7 @@ export const BaseLink = forwardRef(function Link(
142142
}
143143

144144
return (
145-
<NextLink
146-
locale={locale}
145+
<ChakraLink
147146
onClick={() =>
148147
trackCustomEvent(
149148
customEventOptions ?? {
@@ -155,16 +154,15 @@ export const BaseLink = forwardRef(function Link(
155154
)
156155
}
157156
{...commonProps}
157+
as={NextLink}
158158
>
159159
{children}
160-
</NextLink>
160+
</ChakraLink>
161161
)
162162
})
163163

164164
const InlineLink = forwardRef((props: LinkProps, ref) => {
165-
const { locale } = useRouter()
166-
167-
return <BaseLink data-inline-link ref={ref} locale={locale} {...props} />
165+
return <BaseLink data-inline-link ref={ref} {...props} />
168166
})
169167

170168
export default InlineLink

src/components/Staking/StakingHowSoloWorks.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable react/jsx-key */
2-
import { Link } from "@chakra-ui/next-js"
32
import { Center } from "@chakra-ui/react"
43

54
import { Image } from "@/components/Image"

src/components/Staking/StakingLaunchpadWidget.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useState } from "react"
22
import { useTranslation } from "next-i18next"
33
import { FaTools } from "react-icons/fa"
4-
import { Link } from "@chakra-ui/next-js"
54
import { Box, chakra, Flex } from "@chakra-ui/react"
65

76
import { ButtonLink } from "@/components/Buttons"

yarn.lock

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,13 +1734,6 @@
17341734
aria-hidden "^1.2.3"
17351735
react-remove-scroll "^2.5.6"
17361736

1737-
"@chakra-ui/next-js@^2.1.5":
1738-
version "2.2.0"
1739-
resolved "https://registry.yarnpkg.com/@chakra-ui/next-js/-/next-js-2.2.0.tgz#80959c19f7509802c21dd73e23c32c60d918e4c7"
1740-
integrity sha512-brCz0UEOlImX4Np2jDIaljZJkW6kiDSuXG5erxvYjZlklLhmti1zj0o1sSjt5yff1xndfgHoOJb+BYG5wx+vDg==
1741-
dependencies:
1742-
"@emotion/cache" "^11.11.0"
1743-
17441737
"@chakra-ui/[email protected]":
17451738
version "2.1.2"
17461739
resolved "https://registry.yarnpkg.com/@chakra-ui/number-input/-/number-input-2.1.2.tgz#dda9095fba6a4b89212332db02831b94120da163"

0 commit comments

Comments
 (0)