-
Notifications
You must be signed in to change notification settings - Fork 30
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
Allow default content in content_tag in case of noscript/render failure #59
Comments
This comes up relatively often reactjs/react-rails#901 (comment) In general Ruby and JS contexts can't really share anything other than props. You could pass in child html though and dangerously render it to simulate react wrapping ruby content but not really recommended due to the dangerously set inner html call. |
I don't think I was clear enough. I don't care about the content in the block surviving. I just want some default server rendered content that will display if the user has javascript disabled or in the event that the initial mount fails. Think of it like having a |
Ah yes it seems like I misunderstood what you were after, sorry for that. |
I am open to have this feature implemented. With an optional block argument on the |
I'm already using the
This pretty much gets the job done. I think the only improvement would be in the super rare case that javascript is enabled, but somehow the mounting of the component failed. Maybe an error in the bootstrapping of the react component or app, or some browser incompatibility. It's in this case that the react version of the content never shows because of the error, and the noscript version of the content doesn't display because the browser has javascript enabled. I think supporting serverside rendering of the react components would also solve this unique case. I wouldn't say that this is a defect or shortcoming of this gem at all. I only opened the issue because my brain thought "Wouldn't it be cool if it worked like this?", so I tried it. I wouldn't put this high on any priority list since |
I would like to specify some default content that renders serverside within the content tag generated by the
react_component
helper. I've noticed that it defaults to callingcontent_tag
with anil
body and created my ownreact_component_with_defaults
helper like so:This would theoretically allow me to pass a block with default content to render serverside as a fallback in the event of someone having js disabled or a mounting issue when the react js finally executes.
Unfortunately the javascript side of webpacker-react prevents rendering if there is any
innerHTML
to the content tag (See relevant line)Are there any arguments against adding this as a feature? Or is this just something that react wouldn't like with automatic hydration attempts? I'm not knowledgeable enough on react internals to know if this is a bad idea or not.
The text was updated successfully, but these errors were encountered: