Skip to content

Commit d8e5fbe

Browse files
authored
Make external links open in a new tab by default (#193)
* Make external links open in a new tab by default * Fix regression * Fixes * Comment * Run Prettier * Simplify code * Better
1 parent 5ed8c71 commit d8e5fbe

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

components/Link.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,39 @@ export const Link = ({
2323
...props
2424
}: LinkProps) => {
2525
const { locale: currentLocale, extractLocaleFromPath } = useI18n()
26-
const rel = target === '_blank' ? 'noopener' : undefined
2726

28-
// If `href` is undefined or links to an anchor on the same page, bypass `NextLink`
29-
if (href === undefined || (typeof href === 'string' && href.startsWith('#'))) {
27+
let finalHref = typeof href === 'object' ? href.href ?? undefined : href
28+
29+
// If `finalHref` is `undefined`, or if it points to an anchor on the same page, bypass `NextLink`
30+
if (finalHref === undefined || finalHref.startsWith('#')) {
3031
return (
31-
<a href={href} target={target} rel={rel} {...props}>
32+
<a href={finalHref} target={target} {...props}>
3233
{children}
3334
</a>
3435
)
3536
}
3637

37-
const isInternal =
38-
(typeof href === 'string' && href.startsWith('/')) ||
39-
(typeof href === 'object' && !href.host && href.pathname?.startsWith('/'))
38+
const isInternal = finalHref.startsWith('/')
4039

41-
// If the URL is internal, automatically prepend the locale
40+
// If the link is internal, automatically prepend the locale to it
4241
if (isInternal) {
43-
const path = typeof href === 'object' ? href.pathname ?? '' : href
44-
const { locale: pathLocale, pathWithoutLocale } = extractLocaleFromPath(path)
45-
const pathWithLocale = `/${linkLocale ?? pathLocale ?? currentLocale}${pathWithoutLocale}`
46-
if (typeof href === 'object') {
47-
href.pathname = pathWithLocale
48-
} else {
49-
href = pathWithLocale
50-
}
42+
const { locale: pathLocale, pathWithoutLocale } = extractLocaleFromPath(finalHref)
43+
finalHref = `/${linkLocale ?? pathLocale ?? currentLocale}${pathWithoutLocale}`
5144
}
5245

46+
// If the link is external, default the target to `_blank`
47+
const finalTarget = target ?? (!isInternal ? '_blank' : undefined)
48+
5349
const nextLinkProps = {
54-
href,
50+
href: finalHref,
5551
replace,
5652
scroll,
5753
shallow,
5854
prefetch,
5955
}
6056
return (
6157
<NextLink {...nextLinkProps} passHref>
62-
<a target={target} rel={rel} {...props}>
58+
<a target={finalTarget} rel={finalTarget === '_blank' ? 'noopener' : undefined} {...props}>
6359
{children}
6460
</a>
6561
</NextLink>

pages/en/deploying/deploying-a-subgraph-to-hosted.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ The following networks are supported in beta on the Hosted Service:
3737
- `boba`
3838
- `harmony`
3939

40-
4140
> Ropsten, Rinkeby and Kovan are being deprecated, and are no longer supported by the Hosted Service. Read more on the [Ethereum Foundation Blog](https://blog.ethereum.org/2022/06/21/testnet-deprecation). Goerli will be maintained by client developers post-merge, and is also supported by the Hosted Service. Developers who currently use Ropsten, Rinkeby or Kovan as their staging/testing environment are encouraged to migrate to Goerli.
4241
4342
> Note that if an EVM compatible chain is not supported on the Hosted Service, you can run your own [graph-node](https://github.com/graphprotocol/graph-node) to index it.

pages/en/deploying/hosted-service.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: What is the Hosted Service?
33
---
44

5-
> Please note, the Hosted Service will begin sunsetting in Q1 2023, but it will remain available to chains that are not supported on the decentralized network. Developers are encouraged to [migrate their subgraphs](https://thegraph.com/blog/how-to-migrate-ethereum-subgraph) as more chains are supported. Each chain will have their hosted service equivalents gradually sunset to ensure developers have enough time to migrate subgraphs to the decentralized network. Read more about the sunsetting of the Hosted Service [here](https://thegraph.com/blog/sunsetting-hosted-service).
5+
> Please note, the Hosted Service will begin sunsetting in Q1 2023, but it will remain available to chains that are not supported on the decentralized network. Developers are encouraged to [migrate their subgraphs](https://thegraph.com/blog/how-to-migrate-ethereum-subgraph) as more chains are supported. Each chain will have their hosted service equivalents gradually sunset to ensure developers have enough time to migrate subgraphs to the decentralized network. Read more about the sunsetting of the Hosted Service [here](https://thegraph.com/blog/sunsetting-hosted-service).
66
77
This section will walk you through deploying a subgraph to the [Hosted Service](https://thegraph.com/hosted-service/).
88

pages/en/developing/creating-a-subgraph.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ While events provide an effective way to collect relevant changes to the state o
710710

711711
Call handlers will only trigger in one of two cases: when the function specified is called by an account other than the contract itself or when it is marked as external in Solidity and called as part of another function in the same contract.
712712

713-
> **Note:** Call handlers currently depend on the Parity tracing API. Certain networks, such as BNB chain and Arbitrum, does not support this API. If a subgraph indexing one of these networks contain one or more call handlers, it will not start syncing. Subgraph developers should instead use event handlers. These are far more performant than call handlers, and are supported on every evm network.
713+
> **Note:** Call handlers currently depend on the Parity tracing API. Certain networks, such as BNB chain and Arbitrum, does not support this API. If a subgraph indexing one of these networks contain one or more call handlers, it will not start syncing. Subgraph developers should instead use event handlers. These are far more performant than call handlers, and are supported on every evm network.
714714

715715
### Defining a Call Handler
716716

0 commit comments

Comments
 (0)