Skip to content

Deno support #70

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

Closed
JLarky opened this issue Jan 9, 2021 · 9 comments · Fixed by #75
Closed

Deno support #70

JLarky opened this issue Jan 9, 2021 · 9 comments · Fixed by #75
Labels
pr³ ✨ Feature New Feature

Comments

@JLarky
Copy link

JLarky commented Jan 9, 2021

So far it seems like twind works with client side Deno. Either shim or regular (I also tested https://cdn.esm.sh/twind, https://jspm.dev/twind). This is not that surprising given that twind already works as es module in the browser :)

import 'https://cdn.skypack.dev/twind/shim'
import { tw, setup } from 'https://cdn.skypack.dev/twind'

As for server-side support, the first issue is that it just crashes :)

https://cdn.esm.sh/twind/server
https://jspm.dev/twind/server
https://cdn.skypack.dev/twind/server

I guess it happens because of dependency on async rendering for node.

So I tried to create a simple server on Deno that could run on codesanbox https://codesandbox.io/s/deno-twinddev-ssr-p4l2h?file=/src/index.ts

This one is actually not that bad :) it crashes if I try to update to the latest version, but otherwise does most of what I expected twind/server to do :)

p.s. I personally was trying it out in aleph.js but it comes with its own complications that probably would require a separate issue :)

@sastan
Copy link
Collaborator

sastan commented Jan 9, 2021

twind/server is meant to be run only on node js as one of it export is the asyncVirtualSheet which uses async_hooks. The other export is the server side shim method. Sadly this way one can not use shim outside of nodejs.

What about we create twind/shim/server module that exports the shim method? This way you would only need to use twind/server if you want to use the asyncVirtualSheet. All other exports are only re-exports from twind/sheets and could be imported from there. twind/server would still re-export shim from twind/shim/server.

Would this help:

import { shim } from 'twind/shim/server'
import { virtualSheet, getStyleTag } from 'twind/sheets'

// ...

For now that would mean no async rendering for deno. Do you know if there is an async_hooks equivalent?

@JLarky
Copy link
Author

JLarky commented Jan 10, 2021

I probably don't know enough about how to use SSR to answer all of this :) but this sounds reasonable :)

as for async_hooks, I have no idea what that is, but from a quick look at docs it seems like it's experimental and there are no plans to support it in Deno any time soon denoland/deno#945

also if it's experimental with node.js it seems that twind/server is going to have 3 environments it might run: old node.js with no async_hooks support, new node.js, and Deno :) and only 1 of those 3 is going to work :)

@sastan
Copy link
Collaborator

sastan commented Jan 10, 2021

I probably don't know enough about how to use SSR to answer all of this :) but this sounds reasonable :)

Why did you then try to import twind/server?

as for async_hooks, I have no idea what that is, but from a quick look at docs it seems like it's experimental and there are no plans to support it in Deno any time soon denoland/deno#945

Thanks. Good to know.

also if it's experimental with node.js it seems that twind/server is going to have 3 environments it might run: old node.js with no async_hooks support, new node.js, and Deno :) and only 1 of those 3 is going to work :)

twind/server is only required for async rendering in node.js environment where we test it and it works in v12 and v14 which is good enough for the moment. Additionally we have a notice on top of that doc section. Deno/Node sync rendering of shimmed html should now work by using twind/shim/server.

I'll adjust the docs to make clear that for sync rendering twind/sheets and for the shim twind/shim/server is enough.

@JLarky
Copy link
Author

JLarky commented Jan 16, 2021

Why did you then try to import twind/server?

that's the only thing that is mentioned in https://github.com/tw-in-js/twind/blob/main/docs/ssr.md :)

Deno/Node sync rendering of shimmed html should now work by using twind/shim/server

https://esm.sh/twind/shim/server crashes :)
https://jspm.dev/twind/shim/server is 404
https://cdn.skypack.dev/twind/shim/server is 404

@sastan
Copy link
Collaborator

sastan commented Jan 16, 2021

Why did you then try to import twind/server?

that's the only thing that is mentioned in https://github.com/tw-in-js/twind/blob/main/docs/ssr.md :)

For sync rendering twind/sheets is used. But the header is misleading. Maybe you could provide an PR to fix that 😉

Deno/Node sync rendering of shimmed html should now work by using twind/shim/server

It is not released. We have two other PR we want to include in the next release.

@sastan
Copy link
Collaborator

sastan commented Jan 18, 2021

Release v0.12.0 is published. twin/sheets/server should now work in deno

@aadamsx
Copy link

aadamsx commented Mar 24, 2021

Is there an example repo where somewhere I can see how tailwind is properly integrated with Deno?

@sastan
Copy link
Collaborator

sastan commented Mar 24, 2021

It should "just" work – except for twind/server that is using a node specific package (async_hooks). Do you have any issues?

@bebraw
Copy link
Collaborator

bebraw commented Sep 17, 2021

@aadamsx I have a small example at https://github.com/bebraw/gustwind . It seems to work without shim and sheet.reset though this definitely needs more experimentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr³ ✨ Feature New Feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants