question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

navigate() does not return a Promise

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
github-actions[bot]commented, Apr 12, 2020

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m 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! 💪💜

1reaction
casewalkercommented, Dec 9, 2022

The version is now Gatsby 5 and navigate is still alive and well! And the signature still appears to be wrong!

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - this.navigate.url not working in promise
To solve this issue we can use NgZone inside promise. ... authorize(): Promise<any> { return new Promise((resolve, reject) => { let promise ......
Read more >
navigate(to, { state={}, replace=false }) - Reach Router
Navigate returns a promise so you can await it. It resolves after React is completely finished rendering the next screen, even with React...
Read more >
Router - Angular
An object containing properties that modify the navigation strategy. Optional. Default is { skipLocationChange: false } . Returns. Promise<boolean> : A Promise ......
Read more >
Class: CoreRouter - Oracle
Errors encountered during navigation are returned as Promise rejections, and can be caught with the catch() method.
Read more >
Waiting for the result of a Navigation - Vue Router
A navigation guard aborts the navigation by doing return false . A new navigation guard takes place while the previous one not finished....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found