Gatsby: navigate() does not return a Promise

Created on 10 Mar 2020  路  8Comments  路  Source: gatsbyjs/gatsby

Description

When importing the navigate function

Steps to reproduce

import { navigate } from "gatsby"

navigate("/somewhere/").then(doSomething)

Expected result

When the navigation completes, doSomething should be called.

Actual result

This throws an error because navigate() returns undefined instead of an expected Promise (see type).

Looks like gatsby-link is wrapping that function using a global variable:
https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-link/src/index.js#L202-L204

Instead of @reach/router's navigate as indicated in the types.

When I use the one from @reach/router, it works, but is it safe to do so?

Environment

  System:
    OS: macOS 10.15.3
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    Yarn: 1.21.1 - ~/.nvm/versions/node/v10.15.3/bin/yarn
    npm: 6.13.6 - ~/.nvm/versions/node/v10.15.3/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 80.0.3987.132
    Firefox: 72.0.2
    Safari: 13.0.5
  npmPackages:
    gatsby: ^2.17.15 => 2.19.35
    gatsby-image: ^2.2.33 => 2.2.43
    gatsby-plugin-google-analytics: ^2.1.27 => 2.1.37
    gatsby-plugin-manifest: ^2.2.28 => 2.2.45
    gatsby-plugin-netlify: ^2.1.25 => 2.1.34
    gatsby-plugin-offline: ^3.0.21 => 3.0.38
    gatsby-plugin-react-helmet: ^3.1.15 => 3.1.23
    gatsby-plugin-sharp: ^2.3.0 => 2.4.9
    gatsby-plugin-sitemap: ^2.2.21 => 2.2.28
    gatsby-plugin-styled-components: ^3.1.13 => 3.1.20
    gatsby-plugin-typescript: ^2.1.18 => 2.2.2
    gatsby-source-contentful: ^2.1.59 => 2.1.93
    gatsby-source-filesystem: ^2.1.37 => 2.1.51
    gatsby-transformer-inline-svg: ^0.0.7 => 0.0.7
    gatsby-transformer-sharp: ^2.3.5 => 2.3.18
stale? bug

All 8 comments

I'm not sure if it was ever intended to return promise (and thus typings are wrong). Making navigate return promise might be difficult to implement (because we would actually wait for new path template to render before resolving the promise)

Hiya!

This issue has gone quiet. Spooky quiet. 馃懟

We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 馃挭馃挏

Hey again!

It鈥檚 been 30 days since anything happened on this issue, so our friendly neighborhood robot (that鈥檚 me!) is going to close it.
Please keep in mind that I鈥檓 only a robot, so if I鈥檝e closed this issue in error, I鈥檓 HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 馃挭馃挏

I've also run into this issue. What's the word, wrong typings?

Please document, thanks! :purple_heart:

@dandv PR welcome ;)

@antoinerousseau: I was told navigate would be deprecated.

@dandv so why suggest documenting it?

Because I suggested documenting that it's not available during SSR before being told it would be deprecated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

signalwerk picture signalwerk  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments

benstr picture benstr  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments

ferMartz picture ferMartz  路  3Comments