[PLAY-3123] Rails Playground POC - #6359
Conversation
Adds a Rails Playground tab for select kit pages that reuses the existing props panel but renders previews through a server-side pb_rails endpoint. Includes ERB codegen, live preview wiring, and translation for JSX/ERB children so compound kits (card, flex, dialog) behave like their React playground counterparts.
| title: "Header Title inside Dialog.Header", | ||
| }), | ||
| @children.present? ? render_pb_kit("dialog/dialog_body") { @children.to_s.html_safe } : render_pb_kit("dialog/dialog_body", { text: "" }), | ||
| render_pb_kit("dialog/dialog_footer", { |
There was a problem hiding this comment.
Can we avoid calling html_safe on playground-provided children unless the content came from a trusted renderer? The generic children fallback and dialog subcomponent body here look like they can return raw user-entered HTML. Since LiveExampleRails later executes inline scripts from the rendered HTML, this feels like a risky path for security issues, like we had for the previous playground.
There was a problem hiding this comment.
Agreed. I updated this to escape the playground-provided children.
| const data = await response.json(); | ||
|
|
||
| if (!response.ok) { | ||
| setError(data.error || "Failed to render Rails preview"); |
There was a problem hiding this comment.
Should we clear html here as well when a Rails preview request errors or when a new request starts? Right now a failed prop combo can show an error while still rendering the last successful preview
There was a problem hiding this comment.
Updated when a new request starts!
Plain children from the props panel are escaped via TrustedHtml. Dialog body and other fallbacks use ChildrenRenderer instead of raw html_safe.
kangaree
left a comment
There was a problem hiding this comment.
Thanks so much for your review! I'm still working on your feedback, but wanted to provide some updates for now.
| const data = await response.json(); | ||
|
|
||
| if (!response.ok) { | ||
| setError(data.error || "Failed to render Rails preview"); |
There was a problem hiding this comment.
Updated when a new request starts!
| title: "Header Title inside Dialog.Header", | ||
| }), | ||
| @children.present? ? render_pb_kit("dialog/dialog_body") { @children.to_s.html_safe } : render_pb_kit("dialog/dialog_body", { text: "" }), | ||
| render_pb_kit("dialog/dialog_footer", { |
There was a problem hiding this comment.
Agreed. I updated this to escape the playground-provided children.
Run inline scripts first. Then one PbKitRegistry rescan and mountComponents call scoped to the preview container. Rescan again when scripts use deferred DOMContentLoaded/load callbacks.
ElisaShapiro
left a comment
There was a problem hiding this comment.
The only thing that pops out to me vs. React side is the code snippet not having its syntax highlighted (doc code snippets + react playground use react-syntax-highlighter) but that's small potatoes compared to the rest (and definitely not a blocker for this, can be explored at any time in the playground POC/beta life-cycle). Really awesome job!
Allowlist nested child kits, escape remaining text fallbacks, and disable inline script execution in the playground preview.
…Buffers are trusted
There was a problem hiding this comment.
Rails Playground POC looks sound overall: kit allowlisting, nested child-kit checks, HTML escaping, and disabling script re-execution on playground previews cover the main risk paths. No concrete correctness or security issues stood out in the diff under normal usage.
|
Merging master to get the new Icon fixes - #6401. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 24 hours if no further activity occurs. |
Cap request/children size and nesting depth, add a cache-based per-IP rate limit, and return generic client errors while logging detail.
Reject unknown keys and never forward html_options/data/aria/style. Apply the same PropFilter to nested JSX/ERB child props.
|
I addressed feedback:
|
What does this PR do?
https://runway.powerhrg.com/backlog_items/PLAY-3123
Adds a Rails Playground tab for select kit pages that reuses the existing props panel but renders previews through a server-side pb_rails endpoint. Includes ERB codegen, live preview wiring, and translation for JSX/ERB children so compound kits (card, flex, dialog) behave like their React playground counterparts.
Kits:
Screenshots: Screenshots to visualize your addition/change

How to test? Steps to confirm the desired behavior:
Checklist:
enhancement,bug,improvement,new kit,deprecated, orbreaking. See Changelog & Labels for details.milanolabel to show I'm ready for a review.minor,major, orpatchlabel for release.inactive RClabel if not an active RC.