denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.04k stars 5.39k forks source link

[fresh@2.0] unexpected js error with deno 2.0.1+, incorrect chunks order #26616

Open mindon opened 3 weeks ago

mindon commented 3 weeks ago

Version: Deno 2.0.1+

https://github.com/denoland/fresh/issues/2714

jsr:@fresh/core@2.0.0-alpha.23 works fine with Deno 2.0.0, but not 2.0.1+ with an js error

image
marvinhagemeister commented 3 weeks ago

That error always occurs when there are multiple instances of Preact being used at the same time. They don't know about each other. Running deno info main.ts might reveal where the other copy of Preact is getting pulled in.

mindon commented 3 weeks ago

That error always occurs when there are multiple instances of Preact being used at the same time. They don't know about each other. Running deno info main.ts might reveal where the other copy of Preact is getting pulled in.

thanks.

jsr:@preact-icons/tb deps @preact-icons/common deps npm:preact@^10.22.1, while others such as @preact/signals-core@1.8.0 deps @preact/10.24.3

one more question is that the deno 2.0.0 works, and 2.0.1+ not, so i thought this would be a deno issue

multiple versions of deps is very common situation, it matters.

bartlomieju commented 3 weeks ago

@mindon is there a repo that you could share so we can try this case?

mindon commented 3 weeks ago

it seems the issue comes from chunks import orders of preact-signals, NOT the multiple versions of Preact.

when i use a simple demo project with following islands/Counter.tsx there's only one chunk generated, everything is fine. the Symbol.for("preact-signals") is found in the middle of the only chunk js imported by Counter.js

but if i using the same Counter.tsx in my real project, Counter.js imports 4 chunk js, and Symbol.for("preact-signals") is the very beginning of the first chunk js, the js error happened! (Deno 2.0.1+), under Deno 2.0.0 there're 2 chunk js before the Symbol.for("preact-signals").

@bartlomieju here's how the output diff build with Deno 2.0.0 and 2.0.4 Counter_js-Deno_v2.0.0-vs-v2.0.4.zip

import { useSignal } from "@preact/signals";

export default function Counter() {
  const s = useSignal(1);
  return (
    <>
      <div>{ s.value }</div>
    </>
  );
}