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

Circulars dependencies are causing infinite loop #1193

Closed
layershifter opened this issue Jan 20, 2023 · 1 comment · Fixed by #1185
Closed

Circulars dependencies are causing infinite loop #1193

layershifter opened this issue Jan 20, 2023 · 1 comment · Fixed by #1185
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: rollup 🗞️ Issue is related to rollup bundler bundler: webpack 📦 Issue is related to webpack bundler cat: performance 🚀 Issue is related to performance needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@layershifter
Copy link
Contributor

layershifter commented Jan 20, 2023

Environment

  • Linaria version: @linaria/babel-preset@4.3.3, @linaria/react@4.3.3, @linaria/webpack-loader@4.1.11
  • Bundler (+ version): Webpack 5
  • Node.js version: 16
  • OS: N/A

Description

The issue happens in the real project, there we will have following import path:

{
  name: '<root>/packages/data/data-resolver-types/generated/foo.ts',
  children: [
    {
      name: '<root>/packages/data/data-types-common/index.ts',
      children: [
        {
          name: '<root>/packages/data/data-types-common/src/fragments/index.ts',
          children: [
            {
              name: '<root>/packages/data/data-types-common/src/fragments/baz.ts',
              children: [
                {
                  name: '<root>/packages/data/data-types-common/index.ts',
                  circular: true
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Notice that <root>/packages/data/data-types-common/index.ts is circularly referenced.

Webpack successfully builds such code, but once @linaria/webpack-loader is in place build freezes (actually it's an infinite loop).


The easiest way to find out that is to go to node_modules/@linaria/babel-preset/lib/transform-stages/1-prepare-for-eval.js and modify it to log active mutexes:

const mutexes = new Map();
+setInterval(() => {
+   console.log('mutexes', mutexes)
+}, 2000)

It outputs something like that:

mutexes Map(3) {
  '/linaria-circulars-issue/src/index.js' => Promise { <pending> },
  '/linaria-circulars-issue/src/pkg-a/index.js' => Promise { <pending> },
  '/linaria-circulars-issue/src/pkg-a/styles.js' => Promise { <pending> }
}

Notice: these promises will be never resolved 💥

I created a simple repro of this in https://github.com/layershifter/linaria-circulars-issue. In my simplified case Webpack does not go into infinite loop, it just outputs nothing:

$ yarn b:webpack:linaria
...

Without circulars it complies successfully:

$ yarn b:webpack:linaria-no-circulars
asset main.js 2.31 KiB [compared for emit] (name: main)
asset styles.css 24 bytes [compared for emit] (name: main)
Entrypoint main 2.33 KiB = styles.css 24 bytes main.js 2.31 KiB
orphan modules 2.79 KiB (javascript) 937 bytes (runtime) [orphan] 8 modules
runtime modules 274 bytes 1 module
webpack 5.75.0 compiled successfully in 520 ms

I also tried Webpack, Rollup and esbuild without Linaria, all they pass:

$ yarn b:webpack
asset main.js 690 bytes [emitted] (name: main)
orphan modules 338 bytes [orphan] 4 modules
./src/index.js + 4 modules 488 bytes [not cacheable] [built] [code generated]
webpack 5.75.0 compiled successfully in 57 ms
$ yarn b:rollup

./src/index.js → ./dist/rollup/main.js...
(!) Circular dependency
src/pkg-a/index.js -> src/pkg-a/styles.js -> src/pkg-a/index.js
created ./dist/rollup/main.js in 19ms

Notice that Rollup complains about circulars, but builds it

yarn b:esbuild

  dist/esbuild/main.js  801b 

⚡ Done in 3ms

Reproducible Demo

@layershifter layershifter added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Jan 20, 2023
@github-actions github-actions bot added bundler: rollup 🗞️ Issue is related to rollup bundler bundler: webpack 📦 Issue is related to webpack bundler cat: performance 🚀 Issue is related to performance and removed needs: triage 🏷 Issue needs to be checked and prioritized labels Jan 20, 2023
@Anber Anber closed this as completed in af78327 Feb 2, 2023
@towry
Copy link

towry commented Feb 7, 2023

After upgraded to latest version, the infinite loop issue seems still exists.

截屏2023-02-07 09 11 59

stuck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: rollup 🗞️ Issue is related to rollup bundler bundler: webpack 📦 Issue is related to webpack bundler cat: performance 🚀 Issue is related to performance needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants