-
Notifications
You must be signed in to change notification settings - Fork 755
prerendering warning #555
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
Comments
Thanks for reporting this and digging in to see what it was! Just curious, does this happen all the time, or only when there are one or more messages for I don't use server rendering, so I haven't noticed it! I wonder what's the best way to handle this ... On the one hand, we could bring your patch into the gem and re-shuffle the rendered HTML after it's been turned into a string. On the other hand, it seems like we could have a simpler, more programmatic approach since we have access to the gem internals. So what other way could we organize this ... hmm... |
I would fix it in the gem properly... I just did it that way as a quick test... let me see if I can give you a PR Oh and I would guess there has to be at least one message.... the problem is I am using reactrb which always puts at least one message in there, so we ALWAYS see it :-) Its been that way for over a year, just have not gotten around till now to investigate it... |
So I looked at the way this works, and its going to be tough to reorganize things internally: the prerenderer is what packages this all up as a rendered component followed by a script block. The redesign would want to look like something where the outer wrapper component tag, and options is passed into the pre-rerender. But this would then be a breaking change to the pre-rerenderer which I think by design is meant to be an API! So I hate to say it but my patch may be the only practical way forward. Do you want me to do a PR that updates the string before its returned? |
The other options I could think of, none of which were very good:
|
yeah I agree there are solutions which are much better, but they will break the API won't they? I guess the replay_logger solution would work assuming that if no "logger" is supplied the API works as today, and adds the logging internally like it does now. Okay I can give this a try but it will be in a week or so... |
I have the same problem: impossible to prerender anymore |
You can put this code in an initializer, for example # console_replay puts a <script> tag inside the <div data-react-class>...</div>,
# which causes React to warn that it tried to reuse some HTML but failed.
# So, capture the output of the `react_component` call, then find that <script> tag
# and move it _outside_ the <div data-react-class>...</div>. That way,
# React can successfully reuse the HTML.
class React::Rails::ComponentMount
alias_method :old_react_component, :react_component
def react_component(component_name, props = {}, options = {}, &block)
prerender_output = old_react_component(component_name, props, options, &block)
prerender_output
.gsub("\n","")
.gsub(/(<script>.*<\/script>)<\/div>$/,'</div>\1').html_safe
end
end Does that work for you? |
@rmosolgo Thank you so much! But now the content is well rendered, before your workaround I had a white page. |
Oh, I may have made an error in adapting catmando's workaround. I've updated my previous post to include |
@rmosolgo fixed! thank you for taking the time to help me 👍 |
hey @rmosolgo, I've used the same workaround on another app, and now the Do you know where it comes from? |
I don't know where it comes from! Could you open a new issue? It should include:
|
Addressing this in #691 with couple changes:
|
I have another issue to discuss.
I am getting "Warning: render(): Target node has markup rendered by React, but..." This is due to the script block that contains console error messages being in the surrounding container div generated by react_component.
I got rid of this by the following monkey patch (which simply moves to script block outside of the outer container div, and removes all linefeeds), but was wondering why nobody else has noticed, it - perhaps I am doing something wrong?
The text was updated successfully, but these errors were encountered: