-
Notifications
You must be signed in to change notification settings - Fork 131
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
Working with pre-rendered html from a static-site-generator #390
Comments
Oh, I just saw this thread: #190 Is my question the same as laterne's? (I haven't worked with react before so I couldn't tell if we were asking the same question) |
That's something I want to add soon. At the moment it just blasts everything away and re-renders to be safe. We could just leave the HTML in there and try and render as normal, but if even one element is wrong it could blow up the diff and weird things will happen. To do it properly we'd need some sort of hash of the content so we can tell that the server-rendered content is exactly the same. Another option would be to make it "self-healing", in that if it gets to a node and notices that it's incorrect it destroys the node and recreates it rather than throwing an error. That would probably be the most user-friendly approach and would probably take place somewhere near this line. |
I see, this explains these lines in app/index.js. Cool. I like the self-healing idea. So how do you plan to parse the pre-existing HTML into a virtue element? (so that we can diff it with the to-be-rendered vnode and return a set of actions to be feed into patch in update.js) Any library you have in mind? |
Oh wait. I think I understand what you mean now. You don't plan to parse the pre-existing HTML into a virtue element. Instead, you intend to let the vnode (i.e., which is passed into the DOM renderer) to represent the DOM (even if it may be different from the actual virtue representation of the DOM) and only have it fixed when the difference is detected at a That's truly minimalistic and elegant 👍 |
^ Yup that'd be the plan. That might be a bigger feature. But I'll have a look at it this weekend. I really want to ship the final v2. |
What do you think of this implementation: Inside
and for the function returned by If you think this is looking fine I can have some tests written & the self-healing feature implemented (according to this) and send you a PR around this friday or saturday (and then just let me know how you think about it (e.g. if there's any part needs to be improved or reimplemented)). |
Awesome! If you want to work on that, that would be fantastic. I'm not 100% sure about the implementation yet. You'd need to do something around checking the The main downside is that these extra operations will slow down the diffing and updating process. So we'd probably want to only do this on the first run eventually. It seems like it could be slightly complex, but not impossible. If you have any questions about the code within deku just let me know and I'll help you out :) |
Yup, that's what I planned to do.
That's what I thought as well.
Sure! Thanks. I will get started then. |
I also think we should include an attribute for the container to indicate that it has been pre-rendered i.e. in
and in the local
Once the feature is implemented, the |
So at the moment I'm coding according to the following specification: for container with pre-rendered HTML (i.e., with
According to this, the developer may face a situation where: in the html: <div id="container" preRendered><span>Meow</span></div> in the js: let render = createDOMRenderer(document.getElementById("container")
render(<span>Thrr</span>)
//nothing would happen
render(<span>Thrr</span>)
//self-healing should be executed. which is to say, according to the specification, in the second call to render, the action Let's consider the specification where in the second call to So now the question is: what is the purpose of the self-healing feature?
|
So for now, should I implement the |
In the end I think it is good to use an approach similar to react. |
Yeah I'm happy to go with the checksum approach. That will solve most of the use-cases. |
I'm still pretty new to the Virtual DOM paradigm so I've got a question about working with pre-rendered html in deku:
Suppose I am using a static-site generator like Hakyll and I have it compiled an
index.html
andindex.js
for the home page.The
index.html
works just fine by itself so that anyone using w3m or any non-JS browser can still use the site. On the other hand, theindex.js
is a deku script that adds in some nice js magic to the UI (for those with up-to-date browsers). According to the doc, the first time I dorender(v)
(whererender = createApp(document.body)
), it would re-render everything indocument.body
with HTML elements that can be manipulated depending on how the virtual elementv
is defined. So let's say in theindex.html
, the children ofdocument.body
are the exact same elements to be rendered by the first call ofrender(v)
.Is there a way to avoid the re-rendering? (From the doc it doesn't look like the diff-ing algorithm would be able to tell if they are the same.)
The text was updated successfully, but these errors were encountered: