QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.67k stars 1.29k forks source link

[🐞] Optimizer Issue: "implicit$FirstArg" Functionality Error #5251

Open devcaeg opened 11 months ago

devcaeg commented 11 months ago

Which component is affected?

Qwik Optimizer (rust)

Describe the bug

There is an issue with the Qwik optimizer. This problem did not occur in previous versions, though I can't specify from which version it started. When trying to execute a function wrapped in "implicit$FirstArg", the following error message appears: "Optimizer should replace all usages of $() with some special syntax. If you need to create a QRL manually, use inlinedQrl() instead." This error prevents the application from continuing to run.

This error is affecting libraries like ModularForms by the creator @fabian-hiller. Although there's an issue (fabian-hiller/modular-forms#135) opened in the ModularForms repository, the root of the problem lies in Qwik.

Reproduction

https://stackblitz.com/edit/qwik-starter-juwwvd?file=src%2Froutes%2Findex.tsx

Steps to reproduce

  1. Click on the reproduction link
  2. Execute "npm install && npm run dev"
  3. Wait a few seconds and the error will appear in the console

System Info

System:
    OS: macOS 14.0
    CPU: (8) arm64 Apple M2
    Memory: 187.64 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.8.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.8.1 - /opt/homebrew/bin/npm
    pnpm: 8.8.0 - /opt/homebrew/bin/pnpm
    Watchman: 2023.09.25.00 - /opt/homebrew/bin/watchman
  Browsers:
    Safari: 17.0
  npmPackages:
    @builder.io/qwik: 1.2.12 => 1.2.12 
    @builder.io/qwik-city: 1.2.12 => 1.2.12 
    undici: 5.25.2 => 5.25.2 
    vite: 4.4.9 => 4.4.9

Additional Information

The error in StackBlitz differs slightly from a local execution. In local mode (development mode), the error is displayed in both the console and the browser screen. However, in StackBlitz, the error appears in the console with a different message and prevents the project from starting.

mhevery commented 11 months ago

I get this errer instead:

Error: `line` must be greater than 0 (lines start at line 1)
    at originalPositionFor$1 (/home/projects/qwik-starter-juwwvd/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:10169:19)
    at eval (/home/projects/qwik-starter-juwwvd/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:55782:25)
    at eval (/home/projects/qwik-starter-juwwvd/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:55773:21)
    at ssrRewriteStacktrace (/home/projects/qwik-starter-juwwvd/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:55772:10)
    at ssrFixStacktrace (/home/projects/qwik-starter-juwwvd/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:55825:24)
    at Object.ssrFixStacktrace (/home/projects/qwik-starter-juwwvd/node_modules/vite/dist/node/chunks/dep-3b8eb186.js:65006:13)
    at eval (/home/projects/qwik-starter-juwwvd/node_modules/@builder.io/qwik/optimizer.cjs:2897:18)
mhevery commented 11 months ago

Could you help us by bisecting which change is causing the issue.

You can install @builder.io/qwik from https://github.com/BuilderIO/qwik-build. Edit package.json

"@builder.io/qwik": "github:BuilderIo/qwik-build#SHA",

Where the SHA is a specific SHA from https://github.com/BuilderIO/qwik-build In this way you could help us a lot.

devcaeg commented 11 months ago

Hi @mhevery,

Yes, the error "Error: `line` must be greater than 0 (lines start at line 1)..." is the one that appears in Stackblitz, which for some reason is different from the one that appears running the project locally.

devcaeg commented 11 months ago

@mhevery

I've pinpointed the source of the error, and it appears to be an issue that has been present for some time. The problem emerges starting from version "0.19.0" with the message: [vite] Internal server error: Optimizer should replace all usages of $() with some special syntax. If you need to create a QRL manually, use inlinedQrl() instead.

The immediately preceding version, "0.18.1", as well as its predecessors, display a different error but linked to the same code. The associated error messages are:

[vite] Internal server error: Reference to identifier declared at the root 'test$'. It needs to be exported in order to be used inside a Qrl($) scope.

[vite] Internal server error: Found 'test$' but did not find the corresponding 'testQrl' exported in the same file. Please ensure it is exported and spelled correctly.

In summary, from version "0.19.0" onwards, I encounter the same error, whereas in versions prior to "0.19.0", I come across two different errors.

devcaeg commented 11 months ago

@mhevery

Upon further investigation, I determined that the error [vite] Internal server error: Optimizer should replace all usages of $() with some special syntax. If you need to create a QRL manually, use inlinedQrl() instead. appears starting from this commit in "qwik-build". For some reason, this commit introduces the issue. In the preceding commit, the aforementioned error doesn't show up, but the other two previously mentioned errors do.

P.S.: I might be completely wrong in my conclusions. However, that's as far as my investigation took me.

mhevery commented 11 months ago

WOW, that is a very old commit...

devcaeg commented 11 months ago

I've updated the issue reproduction on StackBlitz. When running "npm run dev", the error is displayed. However, when using "npm run preview", there is no error, but the code doesn't execute fully, as evidenced by some clear console.log (the god of debugging 🤪) messages.

devcaeg commented 10 months ago

Any news on this issue?