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.

next.js example hot reloading bug

See original GitHub issue

I love this loader! Great work!!

Unfortunately, I believe I’ve found a bug in the next.js example. The bug is that the new types that are generated by graphql-let as part of the next-js hot reload action seem to be ignored by the typechecker.

Reproduction steps

  1. npm run dev
  2. Make a change to the schema (e.g. Add a field isActive: Boolean to the User type in the schema). Save the file.
  3. Add this new field to the Viewer query. Save the file.
  4. Add a reference to this new field after the query hook on the index view. Save the file. e.g.:
import withApollo from '../lib/with-apollo'
import Link from 'next/link'
import { useViewerQuery } from '../lib/viewer.graphql'

const Index = () => {
  const { data } = useViewerQuery()

  if (data && data.viewer && data.viewer.isActive) {
    const { viewer } = data
    return (
      <div>
        You're signed in as {viewer.name} and you're {viewer.status} goto{' '}
        <Link href="/about">
          <a>static</a>
        </Link>{' '}
        page.
      </div>
    )
  }

  return <div>...</div>
}

export default withApollo(Index)
  1. In a browser, navigate to localhost:3000

Actual Behavior

New types are ignored: type error reported according to the types initially generated at app start: graphql-let-bug Killing the next.js process and starting it again seems to provide the correct types until another change to the schema occurs i.e. it seems that this bug only occurs during the next.js hot reload action.

Expected Behavior

During the next.js hot reload action, graphql-let properly replaces the generated types with the latest and this is reflected properly by the typechecker.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
piglovesyoucommented, Mar 15, 2020

@deanslamajr Amazing work. I put "*" without consideration, perhaps I might have thought it would respect other deps’s globby and would save a number of total deps or something. I really appreciate your deep investigation and the PR, and slash too, which may make another issue in the future.

Let me close this issue now thanks to your PR. Please let me know if you notice something about graphql-let in your project.

1reaction
deanslamajrcommented, Mar 15, 2020

I think I’ve found the cause of this bug:

The major version of globby is not “locked” in package.json. Consequently, if another package has a dependency on a major version of globby that is too old for graphql-let, graphql-let will use the incorrect version and function incorrectly.

To verify this, there are two different paths to initialize the the next.js example. The first will install a major version of globby (globby@11.0.0) that supports graphql-let correct functionality:

npm init next-app --example with-typescript-graphql with-typescript-graphql-app

The second path will install a much older major version of globby (globby@^6.1.0) that seems to break graphql-let’s stale asset removal:

git@github.com:zeit/next.js.git
cd next.js/examples/with-typescript-graphql
npm i

I was able to verify that by locking the major version of globby to the latest major version (11.0.0), this bug can be avoided. I have created a PR to implement this change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NextJS Hot Reload · Issue #30791 · vercel/next.js - GitHub
Describe the Bug. NextJS keeps refreshing when code is updated, the log below shows what happens. I've read about the warning in other ......
Read more >
Fast Reliable/Hot Reloading in Next.js - Coding Ninjas
The following article discusses the concepts of Hot Reloading in a Next.JS project in detail along with its working and some Debugging ...
Read more >
Hot module reload is not working on my nextjs app
Got help from @felixmosh. There was issue because of my folders were case was not matching route case. Fixed the issues by changing...
Read more >
How to fix the NextJS HMR(hot reload) not working error on ...
When working on NextJS applications inside WSL2, there seems to be an issue with HMR (Hot Reload) not detecting changes to your code...
Read more >
Blog - Next.js 12.3
Improved Fast Refresh: .env , jsconfig.json , and tsconfig.json files now hot reload. ; TypeScript Auto-Install: Add a .ts file to automatically ...
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