Skip to content
Source
Sign inSign up
TanStack/query

Angular: Esbuild always generates chunks for devtools #9078

Closedarnoud-dv(GitHub profile, opens in a new tab) opened this issue 5 comments

Describe the bug

The Angular Query devtools are lazy loaded to optimize startup performance of the app while developing and to minimize bundle sizes.

However, even if the code that performs the lazy load is tree shaken, esbuild wil generate unnessary chunks adding to application deployment size.

Your minimal, reproducible example

https://tanstack.com/query/latest/docs/framework/angular/examples/basic

Steps to reproduce

  • Go to the linked Stackblitz
  • Remove withDevtools from app.config.ts
  • Open the terminal and run npm run build
  • The Angular CLI will now perform an optimized production build
  • Note several lazy chunk files are generated even though there is no reference to withDevtools in the application

Expected behavior

No chunks should be generated for devtools if they are not used

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

N/a

Tanstack Query adapter

angular-query

TanStack Query version

v5.74.7

TypeScript version

No response

Additional context

PR in progress

  1. arnoud-dv(GitHub profile, opens in a new tab) added labelspackage: angular-query

  2. arnoud-dv(GitHub profile, opens in a new tab) added labelspackage: angular-query-devtools

  3. arnoud-dv(GitHub profile, opens in a new tab) added labelspackage: angular-query-experimental

  4. arnoud-dv(GitHub profile, opens in a new tab) added labelspackage: angular-query-devtools-experimental

  5. Hi, did you find reason for this, I also have similar issue with one esm package (which depends on some commonjs modules).

  6. Hi, did you find reason for this, I also have similar issue with one esm package (which depends on some commonjs modules).

    Yes, generating lazy chunks seems to be a separate process from tree shaking in EsBuild. So even when code is tree shaken lazy chunks may still be generated for async imports in the tree shaken code. This does not always happen. The simpler any branching code the better tree shaking and skipping async imports works.

  7. Ok, good to know, in my case, I can't remove async import as it could increase initial bundle size.

  8. @imaksp Depending on your use case you could look at subpath and or conditional exports as in the linked PR that will fix this issue. I found it to be the most reliable solution.

  9. Hi, yes this is good solution, but in my case its coming from third party lib, they export all connectors from single file like this: https://github.com/wevm/wagmi/blob/main/packages/connectors/src/exports/index.ts

    so either Angular bundler should tree shake dynamic imports or lib author need to add subpath exports.

Sign in to join this conversation.