Skip to content

Commit

Permalink
gatsby-link: remove deprecated APIs (#29103)
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts committed Feb 3, 2021
1 parent 563e555 commit e194d0c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 68 deletions.
19 changes: 1 addition & 18 deletions packages/gatsby-link/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from "react"
import { NavigateFn, LinkProps } from "@reach/router"

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface GatsbyLinkProps<TState> extends LinkProps<TState> {
/** A class to apply when this Link is active */
activeClassName?: string
Expand Down Expand Up @@ -41,21 +42,3 @@ export const navigate: NavigateFn
*/
export const withPrefix: (path: string) => string
export const withAssetPrefix: (path: string) => string

/**
* @deprecated
* TODO: Remove for Gatsby v3
*/
export const push: (to: string) => void

/**
* @deprecated
* TODO: Remove for Gatsby v3
*/
export const replace: (to: string) => void

/**
* @deprecated
* TODO: Remove for Gatsby v3
*/
export const navigateTo: (to: string) => void
22 changes: 1 addition & 21 deletions packages/gatsby-link/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createHistory,
LocationProvider,
} from "@reach/router"
import Link, { navigate, push, replace, withPrefix, withAssetPrefix } from "../"
import Link, { navigate, withPrefix, withAssetPrefix } from "../"

beforeEach(() => {
global.__BASE_PATH__ = ``
Expand All @@ -24,16 +24,6 @@ const getNavigate = () => {
return navigate
}

const getPush = () => {
global.___push = jest.fn()
return push
}

const getReplace = () => {
global.___replace = jest.fn()
return replace
}

const getWithPrefix = (pathPrefix = ``) => {
global.__BASE_PATH__ = pathPrefix
return withPrefix
Expand Down Expand Up @@ -243,16 +233,6 @@ describe(`<Link />`, () => {
})
})

it(`push is called with correct args`, () => {
getPush()(`/some-path`)
expect(global.___push).toHaveBeenCalledWith(`/some-path`)
})

it(`replace is called with correct args`, () => {
getReplace()(`/some-path`)
expect(global.___replace).toHaveBeenCalledWith(`/some-path`)
})

describe(`uses push or replace adequately`, () => {
it(`respects force disabling replace`, () => {
const to = `/`
Expand Down
21 changes: 0 additions & 21 deletions packages/gatsby-link/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,31 +272,10 @@ GatsbyLink.propTypes = {
state: PropTypes.object,
}

const showDeprecationWarning = (functionName, altFunctionName, version) =>
console.warn(
`The "${functionName}" method is now deprecated and will be removed in Gatsby v${version}. Please use "${altFunctionName}" instead.`
)

export default React.forwardRef((props, ref) => (
<GatsbyLinkLocationWrapper innerRef={ref} {...props} />
))

export const navigate = (to, options) => {
window.___navigate(rewriteLinkPath(to, window.location.pathname), options)
}

export const push = to => {
showDeprecationWarning(`push`, `navigate`, 3)
window.___push(rewriteLinkPath(to, window.location.pathname))
}

export const replace = to => {
showDeprecationWarning(`replace`, `navigate`, 3)
window.___replace(rewriteLinkPath(to, window.location.pathname))
}

// TODO: Remove navigateTo for Gatsby v3
export const navigateTo = to => {
showDeprecationWarning(`navigateTo`, `navigate`, 3)
return push(to)
}
10 changes: 5 additions & 5 deletions packages/gatsby-link/src/parse-path.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export function parsePath(path) {
var pathname = path || `/`
var search = ``
var hash = ``
let pathname = path || `/`
let search = ``
let hash = ``

var hashIndex = pathname.indexOf(`#`)
let hashIndex = pathname.indexOf(`#`)
if (hashIndex !== -1) {
hash = pathname.substr(hashIndex)
pathname = pathname.substr(0, hashIndex)
}

var searchIndex = pathname.indexOf(`?`)
let searchIndex = pathname.indexOf(`?`)
if (searchIndex !== -1) {
search = pathname.substr(searchIndex)
pathname = pathname.substr(0, searchIndex)
Expand Down
3 changes: 0 additions & 3 deletions packages/gatsby/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export {
default as Link,
GatsbyLinkProps,
navigate,
navigateTo,
push,
replace,
withPrefix,
withAssetPrefix,
} from "gatsby-link"
Expand Down

0 comments on commit e194d0c

Please sign in to comment.