vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.93k stars 26.98k forks source link

API Edge function reports used process.nextTick while it is checking it to exist in facebook/dataloader #44711

Open paales opened 1 year ago

paales commented 1 year ago

Verify canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64
    Binaries:
      Node: 16.17.0
      npm: 8.19.1
      Yarn: 1.19.1
      pnpm: 7.12.2
    Relevant packages:
      next: 13.1.1
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://github.com/graphcommerce-org/graphcommerce/pull/1772

To Reproduce

Try and import facebook/dataloader in an edge function.

Describe the Bug

Nextjs gives an error that a node API 'nextTick' is used. However it actually checks in the code if nextTick is available: https://github.com/graphql/dataloader/blob/420573bc45cc55df096053efd743bcf5e9258c0e/src/index.js#L232-L246

Expected Behavior

I would expect this to just work.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

fdecampredon commented 1 year ago

@paales, to fix the error, just pass setTimeout to the batchScheduleFn option when you create your DataLoader (see: https://github.com/graphql/dataloader#batch-scheduling).

Since setTimeout have a delay of 4ms after 5 timeout on some runtime, it can however create performance issues (see https://github.com/vercel/next.js/discussions/44643)

paales commented 1 year ago

@fdecampredon That might be a solution, still a bug imo :)