Skip to content

Commit

Permalink
fix: useNavigate -> gatsby/navigate (#7197)
Browse files Browse the repository at this point in the history
useNavigate seems to no longer be a thing in some newish version of
gatsby
  • Loading branch information
evanpurkhiser committed Jun 16, 2023
1 parent 54c8e7a commit 8161b40
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
1 change: 0 additions & 1 deletion __mocks__/@reach/router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
...jest.requireActual('@gatsbyjs/reach-router'),
useLocation: jest.fn(),
useNavigate: jest.fn(() => jest.fn()),
};
7 changes: 4 additions & 3 deletions __mocks__/gatsby.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable no-unused-vars */

const React = require("react");
const React = require('react');

module.exports = {
...jest.requireActual("gatsby"),
...jest.requireActual('gatsby'),
graphql: jest.fn(),
navigate: jest.fn(),
Link: jest.fn().mockImplementation(
// these props are invalid for an `a` tag
({
Expand All @@ -18,7 +19,7 @@ module.exports = {
to,
...rest
}) =>
React.createElement("a", {
React.createElement('a', {
...rest,
href: to,
})
Expand Down
16 changes: 6 additions & 10 deletions src/components/hooks/__tests__/usePlatform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* eslint import/no-unresolved: ['error', { ignore: ['@reach'] }] */

import React from 'react';
import {useLocation, useNavigate} from '@reach/router';
import {useLocation} from '@reach/router';
import {act, renderHook} from '@testing-library/react-hooks';
import {useStaticQuery} from 'gatsby';
import {navigate, useStaticQuery} from 'gatsby';

import {PageContext} from '../../pageContext';
import {useLocalStorage} from '../useLocalStorage';
Expand All @@ -28,6 +28,10 @@ const PLATFORMS = [
jest.mock('../useLocalStorage');

describe('usePlatform', () => {
beforeEach(() => {
jest.resetAllMocks();
});

it('uses the default of javascript', () => {
const wrapper = ({children}) => (
<PageContext.Provider value={{}}>{children}</PageContext.Provider>
Expand Down Expand Up @@ -99,9 +103,6 @@ describe('usePlatform', () => {
pathname: '/platforms/ruby/',
});

const navigate = jest.fn();

useNavigate.mockImplementation(() => navigate);
useStaticQuery.mockImplementation(() => ({
allPlatform: {
nodes: PLATFORMS,
Expand Down Expand Up @@ -132,9 +133,6 @@ describe('usePlatform', () => {
pathname: '/platforms/ruby/',
});

const navigate = jest.fn();

useNavigate.mockImplementation(() => navigate);
useStaticQuery.mockImplementation(() => ({
allPlatform: {
nodes: PLATFORMS,
Expand Down Expand Up @@ -182,9 +180,7 @@ describe('usePlatform', () => {
pathname: '/',
search: '?platform=javascript',
});
const navigate = jest.fn();

useNavigate.mockImplementation(() => navigate);
useStaticQuery.mockImplementation(() => ({
allPlatform: {
nodes: PLATFORMS,
Expand Down
5 changes: 2 additions & 3 deletions src/components/hooks/usePlatform.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useContext, useState} from 'react';
import {useLocation, useNavigate, WindowLocation} from '@reach/router';
import {graphql, useStaticQuery} from 'gatsby';
import {useLocation, WindowLocation} from '@reach/router';
import {graphql, navigate, useStaticQuery} from 'gatsby';
import {parse} from 'query-string';

import {PageContext} from 'sentry-docs/components/pageContext';
Expand Down Expand Up @@ -243,7 +243,6 @@ export function usePlatform(
defaultValue: string = DEFAULT_PLATFORM
): UsePlatform {
const location = useLocation();
const navigate = useNavigate();

const pageContext = useContext(PageContext);

Expand Down
6 changes: 3 additions & 3 deletions src/pages/platform-redirect.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {useEffect} from 'react';
import {useLocation, useNavigate} from '@reach/router';
import {useLocation} from '@reach/router';
import {navigate} from 'gatsby';
import {PlatformIcon} from 'platformicons';
import {parse} from 'query-string';

Expand Down Expand Up @@ -45,7 +46,6 @@ export default function PlatformRedirect() {
const platformList = usePlatformList();

const location = useLocation();
const navigate = useNavigate();

const queryString = parse(location.search, {arrayFormat: 'none'});
const path = (queryString.next as string | null) || '';
Expand All @@ -61,7 +61,7 @@ export default function PlatformRedirect() {
if (shouldRedirect) {
navigate(`/platforms/${requestedPlatform}${path}`);
}
}, [navigate, path, requestedPlatform, shouldRedirect]);
}, [path, requestedPlatform, shouldRedirect]);

if (shouldRedirect) {
return null;
Expand Down

1 comment on commit 8161b40

@vercel
Copy link

@vercel vercel bot commented on 8161b40 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sentry-docs – ./

sentry-docs.sentry.dev
sentry-docs-git-master.sentry.dev
docs.sentry.io

Please sign in to comment.