Next.js: Using fetch and Safari

Created on 13 Jan 2017  路  4Comments  路  Source: vercel/next.js

While developing an app I've used a custom server setup with express and I also used fetch.
I had no idea that the latest version of Safari doesn't yet support fetch natively and it took me a while to understand this, so maybe it's possible to add a more friendlier error message?
I ended up using isomorphic-fetch 馃挴

Error message running in dev mode (const app = next({ dir: '.', dev: true });) :

screen shot 2017-01-12 at 10 16 03

Error message running in prod mode (const app = next({ dir: '.', dev: false });) :

screen shot 2017-01-12 at 01 21 38

bug

Most helpful comment

@arunoda seems safari gives worse stacktraces, chrome gives the same one when throwing an error with the error message. I'll have a look into it so you can focus on more pressing issues 馃憤

All 4 comments

In the production, we this is the accepted behaviour. (If something happens in the server).
If you provide us a sample app, we could have a look at it.

@arunoda managed to reproduce this, it's a larger issue than only fetch. Any exception when thrown in getInitialProps will give that callstack.

pages/index.js:

import React from 'react'
import Link from 'next/link'

export default class extends React.Component {
  static async getInitialProps({ req }) {
    if(!req) {
      throw new Error('Error message')
    }
    return {}
  }

  render() {
    return <div><Link href="/test">example</Link></div>
  }
}

pages/test.js:

import React from 'react'
import Link from 'next/link'

export default class extends React.Component {
  static async getInitialProps({ req }) {
    if(!req) {
      throw new Error('Error message')
    }
    return {}
  }

  render() {
    return <div><Link href="/">example</Link></div>
  }
}

@timneutkens So it's working fine in Chrome. Only if Safari?

@arunoda seems safari gives worse stacktraces, chrome gives the same one when throwing an error with the error message. I'll have a look into it so you can focus on more pressing issues 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YarivGilad picture YarivGilad  路  3Comments

rauchg picture rauchg  路  3Comments

wagerfield picture wagerfield  路  3Comments

irrigator picture irrigator  路  3Comments

knipferrc picture knipferrc  路  3Comments