--
You received this message because you are subscribed to the Google Groups "mithril" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mithriljs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Satyam
I tried running the code but it's throwing errors for me (first q/q-io are not declared in package.json, and after that, it appears Windows and path separators aren't playing nice), so I'm mostly going from the description on your message - so please correct me if I say something that is off the mark.
From my understanding, it sounds like you are pre-rendering a Mithril app on the server, and you want it to be downloaded as HTML (for SEO and whatnot) and want Mithril to pick things up on the client-side and run as a normal app.
There's one thread on the issue tracker dealing with this here ( https://github.com/lhorie/mithril.js/issues/60 ). I haven't had time to take @sanderhahn's proof of concept further, but there I suggested that the SEO case can be handled by wrapping the pre-rendered HTML in <noscript> tags. Pre-rendering a *fully functional* application with inline event handlers that does not download Mithril application code is, I think, not possible.
The way data binding works means that template functions must be callable from the client, ....
--
I've done a bit of research into server side rendering and client side hydration of virtual DOM apps.
You shouldn't need to bake it into the framework.
There seems to be three steps- render a mithril app to a string, this can be a module used on the server external from mithril
- hydrate / revive / virtualize a server side rendered DOM into a virtual tree.At this point you probably want to somehow build up a cellCache from the server side rendered DOM.
You then want to re-render your mithril app on the client
and instead of doing a diff+patch on an emptycellCache you do it on a pre-populated cell cache. the process of recreating the virtual DOM on theclient and diffing it into existing HTML will invoke all the config and m.route and event handlers andwhat not.
Since your only creating the virtual DOM on the client and not creating new DOM nodes this is reallycheap and you can re-use all the diff / patch machinery to ensure that the config and event handlersand what not are added back properly.
- deal with the transient state problem.If between the time it takes for the server HTML to get rendered and the javascript to get loaded auser selects an <input> and starts typing, he will have typed before event listeners were added.
This means that when the client javascripts revives the mithril app it will render over the <input>with a value of ''. This is a really painful problem to solve.
Note the first two steps I mentioned can be implemented as separate modules without any changesto mithril.
In fact I would love to collaborate on those modules and support both the mithril and vtreevirtual DOM data structures since they are very similar. We already have https://github.com/marcelklehr/vdom-virtualize
--
Hi Satyam,
It's great that you've already implemented most of this, wanted to give a second neutral opinion so you can double check.
> The `cellCache` you mention and many others are local variables within the closure that returns `m` and inaccessible from the outside.> namely, the `build` function which is a [...] hidden function which cannot be overridden from outside since it is not exposed.
It sounds like build and cellCache should be exposed somehow such that you can work with them
> I would expect that few users would be that fast.
If your javascript takes a few seconds to load on first uncached page request on a lower quality internet connection in india then this will be a problem.
You might not expect that users would be this fast, but you might also be spoiled by how snappy your internet is as a developer.
Now admittedly I think this only really a problem at scale. note this problem does not exist if you do purely client side rendering because there willnever be an <input> without onchange listeners.
> As I said that, unfortunately, is not possible.Then the bug is probably that mithril does not diff itself properly against an existing DOM.
You will have to make sure that calling `m.render()` on a clientside created virtual tree (i.e. rendering your top level controller) does the correct thing, i.e. minimal actual DOM manipulation and calling allthe config props and adding all the event handlers.
Hi SatyamDid you get a chance to look at sanderhahn's code from the link in my first comment? ( https://github.com/sanderhahn/mithril.js/commit/973bbba7eb4505d464d20809d6961151670cd76c )No offense, but I think this thread is kinda just leading back to everything that was said in that thread :)
Anyways, I've been meaning to look into this, but I've just been very busy and imho this feature is lower priority than the other things I was looking into (bugs, lifecycle management, keys, etc).
But if only you allowed it to happen by making accessible (though declared protected) and documenting some of Mithril internals
this would extend the interest in mithril and increase the collaboration, just know, although mithril is pretty interesting I keep using reactjs because I need its isomorphic feature..would be interesting check the community opinion...
again, this seems the most promising framework for the nearly future, I hope the best and I hope than this grown and include "the good parts" from react and maybe ember..thanks!!
This is a bit off topic but similar. Per SEO and rendering only on the front-end, I know google can now search SPA’s. I don’t know if they are 100% at it but They found my static SPA blog. Before searching bilby.js lenses
and my post would show up with !#
in the url. I have since changed to created html files on each page in order to pass the SoundGecko
test, that is, if you don’t like reading or like listening while reading you can use SoundGecko
to convert it to audio. But the pages are very minimal and tell the person to turn on JavaScript with CSS.
If anyone is interested in looking at the static SPA blog built with Mithril you can go to http://jon.prescottprogrammers.com or https://github.com/jon49/programming-blog. It’s not perfect, I’ve been changing things as I learn more but it works!