Skip to content
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

CLJ render-to-string #10

Open
lilactown opened this issue Dec 11, 2018 · 8 comments
Open

CLJ render-to-string #10

lilactown opened this issue Dec 11, 2018 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@lilactown
Copy link
Collaborator

lilactown commented Dec 11, 2018

I'm a bit wary to support this but I see it's benefits, especially when wanting to play with component trees at a REPL.

I honestly think that Node.js will eventually have a much better story once SSR Suspense hits, but in the meantime this can cover a number of use cases.

The trick will be making sure that CLJ rendering == Node.js rendering, and supporting hooks.

@DjebbZ
Copy link

DjebbZ commented Feb 8, 2019

I was going to open this very issue :)

I'm interested into using hx to replace rum, in an isomorphic setup Browser/JVM. I'm talking about a real-world website that makes millions of views per day. The problem with rum is that it deviates too much from React.js, especially since the introduction of hooks.

If you want help with that:

  1. I can provide, time permitting, tests, code reviews and maybe patches!
  2. Look at what rum does in its test suite: it renders rum code to string, then compiles the same code with node.js and compares the output (basically just a =). I think it's a viable strategy.
  3. I haven't check all hooks, but useState in CLJ could just return the initial value and use it to render to initial HTML string. Will be happy to investigate with you the problem space.

My advice, if you permit: keep the layer that hx brings on top of React.js as thin as possible, don't create unnecessary abstractions, or even don't create abstractions at all, and hx would be a killer library that stays as close to React.js as possible, especially since the design of React.js is still a giant real-world WIP. Too dangerous to introduce abstractions that could deviate any time React introduce novelty.

Thanks for reading me!

@pepe
Copy link

pepe commented Feb 8, 2019

@DjebbZ well said. Even as I am pursuing the pure cljs way, This has value.

But the question is if it should be part of the core library?

@DjebbZ
Copy link

DjebbZ commented Feb 8, 2019 via email

@lilactown
Copy link
Collaborator Author

The problem I see is that you wouldn't be able to use any 3rd party Hooks or components which are included from JS-land. I'm also not at all interested in implementing streaming rendering in CLJ, which Node.js SSR will eventually support with React Suspense.

This means that you have to separate your code base between which components and hooks are OK to use on the server vs. client-side only. Perhaps this is OK, since you could use reader-conditionals to ensure this happens. It just might be surprising.

Overall it might be a lot of work and enforce certain restrictions on the user's code that I'm not sure is worthwhile. I am listening though and will continue to consider spending some time on it in the coming weeks.

@DjebbZ
Copy link

DjebbZ commented Feb 9, 2019 via email

@pepe
Copy link

pepe commented Feb 11, 2019

Sorry for the delay.

For me it is mostly project focus, and I am not at all opposed to this idea, nor I have any say in this. Actually sorry for the noise.

@DjebbZ
Copy link

DjebbZ commented Feb 11, 2019

Sure, it's all up to @Lokeh. Maybe he'll consider this feature useless for his use case, or too complex, or too whatever.

@lilactown lilactown added enhancement New feature or request help wanted Extra attention is needed labels Feb 13, 2019
@lilactown
Copy link
Collaborator Author

lilactown commented Mar 16, 2019

What I've done to move the needle on this is completely decouple the hiccup parser from React. The API now is like this:

(def hiccup-config
  {:create-element create-element-impl
   :is-element? is-element-impl
   :is-element-type? is-elemene-type-impl
   :fragment fragment-impl})

(hx.hiccup/parse hiccup-config [:div "Hello, hiccup!"])

This will use the functions provided in the hiccup-config map to transform the tree.

In hx.react, these map to react/createElement, react/isValidElement, etc.

I have pushed a proof of concept HTML string renderer in a separate branch: https://github.com/Lokeh/hx/blob/html/src/hx/html.clj

This would allow someone (either this library, or even an external library) to leverage hx.hiccup for hiccup parsing and implement their own "engine" to generate HTML strings, cljfx maps, or whatever you want while sharing the same hiccup syntax as the hx library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants