markfinger / python-react

Server-side rendering of React components
MIT License
1.62k stars 116 forks source link

How the diff will work in python? #49

Closed abdelouahabb closed 9 years ago

abdelouahabb commented 9 years ago

Hi, sorry for this question, this is the first time I try the react serverside rendering, and when trying to debug, i dident found the react traces (the result is in of course), I downloaded an example here https://github.com/mhart/react-server-example and I can see the react traces, si the diff algorithm could work at the client, here is two screenshots:

this is with:

with

without (hello world)

noreact

markfinger commented 9 years ago

I'm not exactly certain what you mean by the "react traces".

Do you mean:

markfinger commented 9 years ago

I assume you're problems down to that render server that you're using, as it seems to build the app for you as well. The example in this repo only illustrates how to rig up pre-rendering so you can generate markup - it doesn't illustrate how to build the app - so the browser extension can't find a React on the page and hence doesn't show anything.

If you want to build an app, I'd recommend starting at https://github.com/markfinger/python-react#using-react-on-the-front-end

markfinger commented 9 years ago

As an aside, older versions of this library also used to build your codebase, but it proved to be limiting and made deployments difficult. The library you're using that runs your codebase through browserify will be a reasonable place to start, but I'd strongly suggest investigating a more controlled build process before you try to deploy anything.

abdelouahabb commented 9 years ago

@markfinger sorry for the delay, what i meant is that there is no id in the markup, so react could calculate easily what will change in case there will be some other inerractions in the frontend.

markfinger commented 9 years ago

When render_component is called, make sure that the to_static_markup kwarg is False

abdelouahabb commented 9 years ago

Ah, now it works, thank you!

sans titre

abdelouahabb commented 9 years ago

just a question : how about performance? isent that bad to have two servers handle requests? (node and the python app server) ?

markfinger commented 9 years ago

There's overhead on the transport mechanism, but most of the cost in real-world applications will be in React's rendering

abdelouahabb commented 9 years ago

so then it is up for the dev to see what to sacrify? if the application has too much changes in the client side then render once in serverside, but if there is only few rendering at client side, then choose to do all that stuff at the client and free the server to make it only serving files?

markfinger commented 9 years ago

You'll only want to pre-render pages where there's some benefit. Generally speaking, this usually includes landing pages and pages where you want a search engine to crawl it.

As long as your content isn't personalised, you can pre-render everything and let a cache remove any concerns about performance. If you want to pre-render personalised content, then you'll need to start profiling and resolving performance problems. There are dozens of different solutions with different tradeoffs, so it's difficult to advocate for any particular strategy as a catch-all.

abdelouahabb commented 9 years ago

ah, i can see now the beginning, thank you again !