Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Firefox] Unhandled promise rejection TypeError: "this.loadPageDataJson(...).then(...).finally is not a function #16287

Closed
arnauguadall opened this issue Aug 1, 2019 · 17 comments · Fixed by #16734
Assignees
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@arnauguadall
Copy link

Description

When I run in localhost works ok with all the browsers including Firefox but when it goes to production the Firefox v68.0.1 looks misaligned caused (I guess) for this .finally function.

Steps I tried

I tried to use "gatsby-plugin-compile-es6-packages": "^2.1.0" to compile es6 features like they are using in #2177 but without luck.

Also I tried:

exports.modifyWebpackConfig = ({ config, stage }) => {
  switch (stage) {
      case "build-javascript":
          const app = config._config.entry.app;
          config._config.entry.app = [require.resolve("./polyfills"), app];

          break;
      default:
          break;
  }

  return config;
};

Expected result

What should happen?

Works ok with Chrome (v75.0.3770.142).

Chrome version

Actual result

Returns a console error which for what I found it's something that .finally() function is quite new and maybe is not fully supported yet.

Unhandled promise rejection TypeError: 
"this.loadPageDataJson(...).then(...).finally is not a function"

How it looks like in Firefox (v68.0.1)
Firefox version

Also I'm using "antd": "^3.12.3" package to handle the UI and in this CSS class if you change flex-direction: column to row it looks ok but the error still persists.

.ant-layout {
    display: flex;
    flex: auto;
    flex-direction: column;
    min-height: 0;
    background: #f0f2f5;

Environment

System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.16.0 - /usr/local/bin/node
    Yarn: 1.16.0 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  Languages:
    Python: 2.7.10 - /usr/bin/python
  Browsers:
    Chrome: 76.0.3809.87
    Firefox: 68.0.1
    Safari: 12.1.1
  npmPackages:
    gatsby: ^2.0.76 => 2.13.45
    gatsby-image: ^2.0.20 => 2.2.7
    gatsby-mdx: 0.6.3 => 0.6.3
    gatsby-plugin-antd: ^2.0.2 => 2.0.2
    gatsby-plugin-compile-es6-packages: ^2.1.0 => 2.1.0
    gatsby-plugin-google-analytics: ^2.0.9 => 2.1.6
    gatsby-plugin-less: ^2.0.8 => 2.1.2
    gatsby-plugin-manifest: ^2.0.9 => 2.2.4
    gatsby-plugin-offline: ^2.0.16 => 2.2.4
    gatsby-plugin-react-helmet: ^3.0.2 => 3.1.2
    gatsby-plugin-react-svg: ^2.1.1 => 2.1.1
    gatsby-plugin-sass: (internal URL) => 2.0.11
    gatsby-plugin-sharp: ^2.0.18 => 2.2.9
    gatsby-plugin-web-font-loader: ^1.0.4 => 1.0.4
    gatsby-remark-autolink-headers: ^2.0.14 => 2.1.3
    gatsby-remark-copy-linked-files: ^2.0.8 => 2.1.4
    gatsby-remark-images: ^3.0.1 => 3.1.7
    gatsby-source-filesystem: ^2.0.25 => 2.1.7
    gatsby-source-git: ^1.0.1 => 1.0.1
    gatsby-source-graphql: ^2.0.8 => 2.1.3
    gatsby-transformer-remark: ^2.2.4 => 2.6.10
    gatsby-transformer-sharp: ^2.1.8 => 2.2.5
  npmGlobalPackages:
    gatsby-cli: 2.7.9
@elken
Copy link
Contributor

elken commented Aug 1, 2019

Promise.prototype.finally is supported in current firefox but I suspect this could be an upstream bug.

@wardpeet wardpeet self-assigned this Aug 1, 2019
@Chalarangelo
Copy link
Contributor

Is there any easy way to polyfill this for the time being? Some plugin or configuring webpack etc?

I can confirm this is a bug, but only in production mode. If I run it in dev mode, it works just fine.

@elken
Copy link
Contributor

elken commented Aug 3, 2019

It's supported in the browser, there's no need.

@Chalarangelo
Copy link
Contributor

@elken I know it is, but somehow it does not work in FF 68 (which seems to support it), at least in production. This will break my website sooner or later for some users. Can I configure my project in such a way that this does not break the website on FF 68 or older? Thanks in advance! 🙏

@arnauguadall
Copy link
Author

What @Chalarangelo asked would work for me too for now, if there is some workaround until they implement this.

@sidharthachatterjee
Copy link
Contributor

sidharthachatterjee commented Aug 5, 2019

@Chalarangelo According to https://caniuse.com/#feat=promise-finally, finally is supported in Firefox all the way back to Firefox 58 🙂

@arnauguadall Could you please link to a minimal reproduction?

The default starter works fine in Firefox 68
Screenshot 2019-08-05 at 4 18 44 PM

@sidharthachatterjee sidharthachatterjee added the status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. label Aug 5, 2019
@coreyward
Copy link
Contributor

We're experiencing this on Canvas 1839 as well if you care to see it happen, @sidharthachatterjee (source maps are on).

Screen Shot 2019-08-06 at 4 15 54 PM

@coreyward
Copy link
Contributor

coreyward commented Aug 6, 2019

It looks like loader.js is importing a polyfill (import "core-js/modules/es7.promise.finally"), so that might be what's causing the issue.

Specifically, this is triggered when a Gatsby Link is hovered over, which prompts the page-data.json file to be loaded.

@elken
Copy link
Contributor

elken commented Aug 7, 2019

The polyfill should be only required on versions <58, if that's the problem.

@arnauguadall
Copy link
Author

arnauguadall commented Aug 7, 2019

Then @coreyward, could be an alternative change that loader.js to not use .finally() function?

Would be something like include async at the beginning and change .finally() for await.

In loader.js

  async loadPage(rawPath) {

    const inFlight = this.loadPageDataJson(pagePath)
      .then(result => {
        if (result.notFound) {

           // code 

          this.pageDb.set(pagePath, finalResult)
          return pageResources
        })
      })
      // remove .finally()
      /*
      .finally(() => {
        this.inFlightDb.delete(pagePath)
      })
      */

    await this.inFlightDb.delete(pagePath) // use await instead

    this.inFlightDb.set(pagePath, inFlight)
    return inFlight
  }

Maybe another solution would be nest another .then() at the end.

@philJohnson
Copy link

I'm having the same issue with a site as well. I have found that the Firefox Beta has fixed this but that's not released until Sept 3. In their notes it does have a known bug about Promise. Anyone know which version of Gatsby 2 was stable?

@philJohnson
Copy link

FYI, I reverted back to "gatsby": "2.12.0" in my package.json dependencies and it resolved my issues

@coreyward coreyward added type: bug An issue or pull request relating to a bug in Gatsby and removed status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. labels Aug 8, 2019
@coreyward
Copy link
Contributor

@wardpeet You self-assigned this. Do you need more info than the above?

@Chalarangelo
Copy link
Contributor

I can confirm that, for now, reverting to 2.12.0 works fine on Firefox.

@arnauguadall
Copy link
Author

I removed some custom component I had in another folder that I assume they used .finally() function and now are gone. It's ok for temporary solution but would be nice to know why when you combine gatsby/Firefox crashes.

@peter-mouland
Copy link
Contributor

thank guys, i can confirm the break was in 2.12.1. 2.12.0 works for me also.

Here is a fix. https://github.com/gatsbyjs/gatsby/pull/16734/files

I've not used async/await as that would change the behaviour of the function, instead i've opted to dupe the finally code in a then and catch. This mean there is no change in code behaviour.

@wardpeet
Copy link
Contributor

[email protected] has fixed the firefox(finally) bug. Thank you @peter-mouland

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants