denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.6k stars 652 forks source link

feature request: "client-only" islands. #975

Open cowboyd opened 1 year ago

cowboyd commented 1 year ago

Every once in a while we encounter a module that cannot even be loaded on the server because it has top-level references to browser-only objects such as document. This is the case when you try to use the Monaco editor in Fresh.

Basically it blows up just evaluating the module because it wants to look up DOM nodes at the module's top-level.

"Bad behaving" ES modules that refuse to even load on anything but the browser are a fact of life, and it would be nice if Fresh provided a way to specify a placeholder element for the initial render, but only load and run the code of the island on the client.

I don't know what this would look like, but it saves a lot of pain hand-rolling async imports.

cowboyd commented 1 year ago

It appears that the source of the issue is that vscode has binary logic on whether it is running on Node vs Browser, but thinks that Deno is the browser and so it goes ahead and reaches for document. https://github.com/microsoft/vscode/blob/12e6b0b3043f19d0cf1730eb3c213d3930310053/src/vs/base/browser/canIUse.ts#L21-L23

I filed an issue here https://github.com/microsoft/monaco-editor/issues/3501