fresh icon indicating copy to clipboard operation
fresh copied to clipboard

Incorrect transpilation makes DevTools check always falsy

Open marvinhagemeister opened this issue 1 year ago • 4 comments

// This is wrong.
typeof Deno < "u" && window.__PREACT_DEVTOOLS__ && window.__PREACT_DEVTOOLS__.attachPreact("10.15.1", d, {
    Fragment: A,
    Component: T
});

marvinhagemeister avatar Jul 13 '23 19:07 marvinhagemeister

Could esm.sh be serving up a Deno target and rewriting the modules here? It was added 3 weeks ago.

Hypothesis is that esbuild performs imports using the Deno http agent, which has a Deno/ user agent. esm.sh checks the user agent and sets the target to denonext here which causes imported modules to have typeof window string replaced, incorrectly, with typeof Deno. This would break any code destined for the browser.

I tried specifying a target on the import and it does seem to resolve the issue. For example:

- import docsearch from "https://esm.sh/@docsearch/js@3";
+ import docsearch from "https://esm.sh/@docsearch/js@3?target=esnext";

dsosby avatar Jul 15 '23 04:07 dsosby

Any updates or insight on this issue? I was able to load Preact devtools after changing the import map to include npm:preact/debug and npm:preact/devtools; however, I cannot get past a message that says:

Connected, listening for Preact operations... If this message doesn't go away Preact started rendering before devtools was initialized. You can fix this by adding the preact/debug or preact/devtools import at the top of your entry file.

I added these imports to the top of dev.ts to no avail. I tried injecting the import to the main entry through a Fresh plugin too, but that also had no effect.

jasonjgardner avatar Sep 27 '23 12:09 jasonjgardner

The preact/debug import is already injected by Fresh. No need to manually add it. I haven't checked yet with npm: imports, but that's no my to do list.

marvinhagemeister avatar Sep 27 '23 12:09 marvinhagemeister

Happy to report that dev tools work in Fresh 1.5.1 with Preact 10.18.1 🙌

jasonjgardner avatar Oct 13 '23 01:10 jasonjgardner