GithubHelp home page GithubHelp logo

Comments (7)

th0r avatar th0r commented on May 17, 2024

@Sinewyk During server-side rendering React generates checksum (hash) for rendered markup.

If it matches during client-side rendering, React will reuse server-generated DOM and just attach events to it.

If it doesn't, React will throw away all the server-generated DOM and render the "proper" client-side DOM again.

By default React takes this checksum from the root element's attribute data-react-checksum, but in case of react-dom-stream you just don't know it by the time you write this element's html to the stream.
This is why you have to explicitly pass it to the render method on client.

from react-dom-stream.

Sinewyk avatar Sinewyk commented on May 17, 2024

So, theoretically we could do a one liner to attach it manually and use the standard ReactDOM.render, or you could stream that one liner at the end of the parsed html to do it yourself no ?

from react-dom-stream.

th0r avatar th0r commented on May 17, 2024

@Sinewyk This is exactly what react-dom-stream does: https://github.com/aickin/react-dom-stream/blob/master/index.js#L12

from react-dom-stream.

Sinewyk avatar Sinewyk commented on May 17, 2024

For once, I should have looked at the client side implementation first before opening my mouth.

Sorry about that 😊

from react-dom-stream.

th0r avatar th0r commented on May 17, 2024

@Sinewyk Np)

from react-dom-stream.

aickin avatar aickin commented on May 17, 2024

Thanks for the discussion on this, @Sinewyk & @th0r! (It was especially cool to have an issue opened, discussed, and closed all while I was asleep!)

One thing to add: I'm strongly considering getting rid of the client side part of react-dom-stream, but I only had the implementation idea in the middle of last week, and I haven't tested my idea enough yet (also: I'm busy working on v0.2.x, which is more async and uses streams in a smarter way).

Just so you know, and so I get it written down: the basic idea would be for react-dom-stream to go ahead and output a JavaScript inline block after it renders the HTML. That block would do two things:

  1. Set data-react-checksum on the rendered root element.
  2. Remove the JavaScript block itself from the DOM.

Step 2 is necessary because React will get wonky and have errors in render if there are nodes under domElement that weren't rendered by React.

I'm not 100% sure how modern browsers will react to a JavaScript inline block that removes itself from the DOM before onDomReady. I know that IE6 and IE7 used to error out if you modified a node that had not yet been closed, but that was fixed for IE8.

tl;dr: it will require a lot of testing, but there's a chance that in the future you will be able to just use vanilla react-dom to connect to server-generated markup. Cheers!

from react-dom-stream.

aickin avatar aickin commented on May 17, 2024

FYI, I just released version 0.2.0, which allows you to use React's client-side render method. Enjoy!

from react-dom-stream.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.