-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Rendering isomorphically #385
Comments
What in the HTML differs? |
|
Interesting, okay. Maybe we can create and add that editor key after initial render or only when you copy… |
Yep, any work around for this? |
You could… stub out Math.random while doing the initial render? Other than that, not really. You could also look at not rendering the Draft component at all on the server. |
@spicyj it would be cool to get a PR done to get the Math.random replaced as a key. Do you think FB will assign this as a bug? I will work with it as is for now, and consider not rendering isomorphically. Although thats the part I'm really keen on as I have 100% coverage at the moment. Thanks! |
It's mostly not clear what to replace it with. Certainly willing to accept good alternatives but this isn't very high priority for me. |
I understand this key is used to define editor instances? Can we provide a prop for the key, else use math.random? |
@spicyj I'm also getting the following HTML differs in SSR:
on react v15 and latest (0.7.0) draft.js |
hey guys, have you try this method ? |
Any thoughts on this? That method that @reyhansofian mentioned doesnt work :/ |
@spicyj, are there any new updates (any discussions internally on how to tackle this)? I'm getting the same checksum errors while using Draft.js with SSR (react 15.1.0 and draft-js 0.7.0):
I'm loving Draft.js but I'm hoping SSR will be supported in the near future. Keep up the great work! |
@spicyj There is also a side effect bug using this on server side. The generateRandomKeys method would freeze the server once it is called 2^24 times. And in fact, gets extremely inefficient as it grows. |
+1 for fixing this issue |
Try this method to avoid warning. |
@Superoryco yeah, but that's loosing SSR anyway because you don't have a SSRed component, you only have a div. The user won't see anything until all the js loads. I don't think it's a proper solution. |
I have an interesting way for resolving SSR, as for my app, on initial load, it requires only to display text, i am rendering only Not a fan of the solution, but at the moment it works well for me. |
For anyone still wrestling with this I have another workaround. Simply disable the Draft js reliant portion of your component on initial render, then enable it in Example in component class:
|
@greyvugrin it's the same workaround, and I don't think its a workaround, you simply dont use draft in ssr. I need to show the editor in a SSRed reactjs app. |
@spicyj In react 15, react-id is replaced by an index instead. Could we do something similar to replace random keys? |
@gabriel-miranda With the workaround I described, there is a brief flash if using SSR to display the page where the editor is initially missing, but it's pretty negligible. Also if the app is already rendered and you switch to a page there is no flash. The pro is that no user interaction is needed to make the component appear, which is why this is different than the other proposed workaround. Also unless the editor contains data necessary for seo, you can probably not worry about having it missing from the markup as long as the component is usable on load. Maybe give this a shot and see for yourself, it won't take more than a couple mins to rig up, but it's better than it looks! :) |
Would like to warn anyone hoping for SSR again: https://github.com/facebook/draft-js/blob/master/src/model/keys/generateRandomKey.js#L16 The generation method here would run out of keys after 2^24 keys are generated. It also suffers from birthday problem which will degrade server performance over time and freeze eventually closer to 2^24. |
I think this should be high priority |
A hack that seems to work is adding a step in your build process that replaces node_modules/draft-js/lib/generateRandomKey.js with your own version that generates keys based on a counter/seed value. Reset that value before you call render/renderToString on client/server. I can't see any need for the the keys to be unique outside the scope of a single render call on the server. |
It'd be great if we can get a fix in the core library so we're all not building our own workaround that replaces node_modules/draft-js/lib/generateRandomKey.js |
Any progress here? |
Can someone please let us know about status of the implementation of isomorphic rendering in draft js? |
I found this section in the documentation for anyone browsing this issue. They seem to have added a Here's the documentation entry: https://draftjs.org/docs/api-reference-editor#editorkey
|
Draft-js is great! But we are rendering our app isomorpically, draft-js creates a checksum error when doing so? Using react 14.8. Any way we can avoid this?
The text was updated successfully, but these errors were encountered: