Frontend iframe renderer framework: 3D models, OpenAPI#37233
Frontend iframe renderer framework: 3D models, OpenAPI#37233silverwind merged 39 commits intogo-gitea:mainfrom
Conversation
|
But the problem is, the file extensions are ambiguous Without frontend render's trial, backend doesn't know whether the file is really renderable. That's why the old code "tries to render the 3d model, if fails, then hides the rendered button" I think "Use Content-Seucrity-Policy: script nonce #37232" is good enough and safe enough (safer) |
Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
I tested using a broken file and it rendered an error message. Is that not acceptable? |
It means the existing logic is broken, but I don't think it means backend should blindly treat the plenty of potential ambiguous file extensions as 3D model. |
|
Maybe that trial could be restored, but it will be more complicated. |
|
I guess it would need a magic-byte detection in backend but given the numerous formats supported here, it would be complex. |
Yes, that's why the "detection" work was designed to be deferred to the renders. Backend can't be (and shouldn't be) a knowing-everything detector in this case (if we need frontend renders) |
|
In my mind, the complete design is like this (if the iframe will be used):
|
|
So basically do the iframe rendering in frontend, like mermaid does it, with no separate vite entry point script. |
I think so, otherwise I don't see how we could resolve the more potential conflicts in the future if there are more frontend renders and when they declare they can render the same extensions. Unless we are sure that we can do everything in backend and/or there would be no any extension conflict.
IMO no, it's not like mermaid. mermaid is fully rendered in the same origin, it shares the parent's scripts. But for all other general 3rd frontend renders, I think we should make them in different origins. |
|
By the way, since the "broken file render logic" has been broken for a long time and nobody complains (#37233 (comment)) I think we can backport this as long as it doesn't make the situation worse The plan for the future (#37233 (comment)) can be written in the comment as a TODO and leave the refactoring to the future (if anyone complains, or we need to add more frontend renders) |
The backend renderer cannot reliably determine whether an ambiguous extension (*.obj, *.off, *.step, etc.) is actually a 3D model without a render trial, so detection is deferred to the frontend per PR discussion. The plugin now fetches the file in the parent and ships bytes to a sandboxed (null-origin) iframe via postMessage. Background and default colors are read from live CSS and passed in, so the viewer matches the current theme instead of hardcoded values. The raw-file prompt is hidden while loading to avoid a "View Raw" flash, and the container height is set via CSS so the loading spinner has the same dimensions as the final rendered viewer. Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
|
All done, and this renderer also now has a e2e test. |
Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
Pull request was converted to draft
|
Given that padding/color is such a recurring issue, should add a assertion in the e2e for it. I can do after your fixes. |
|
Should be right now. Before: the external render helper can read the query parameter directly. After using "srcdoc": the query parameter can only be passed via the script's data attribute |
|
Will re-verify all and add e2e assertions in a bit, currently branch is occupied with another change and I don't wanna do a worktree right now 😆. |
- assertFlushWithParent helper: child has no horizontal inset from parent — catches padding/border anywhere in between - 3D, openapi, pdf, external tests assert iframe/container is flush with .file-view (regression for the .markup-class padding) - 3D test asserts iframe body bgcolor matches parent body bgcolor - eslint: add browser globals to e2e test config so page.evaluate callbacks don't trip no-undef Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
e2e tests added for padding and 3d bg color. renderers manually tested. |
Throw on null narrows via control-flow analysis instead. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Move the post-build manifest-patching work in `iifePlugin` from the `closeBundle` hook to `writeBundle`. `closeBundle` fires via `bundle.close()` in Vite's `finally` block, so a throw there replaces the real compile error from `catch`. `writeBundle` runs only on a successful `bundle.write()`, so the manifest is guaranteed to exist and a throw propagates cleanly. This lets us drop the defensive try/catch that silently let builds succeed with a stale manifest (flagged by Copilot in go-gitea#37233 and by the FIXME comment left behind). Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
I was unable to create a backport for 1.26. @silverwind, please send one manually. 🍵 |

Introduces a frontend external-render framework that runs renderer plugins inside an
iframe(loaded viasrcdocto keep the CSPsandboxdirective working without origin-related console noise), and migrates the 3D viewer and OpenAPI/Swagger renderers onto it. PDF and asciicast paths are refactored to share the samedata-render-namemechanism.Adds e2e coverage for 3D, PDF, asciicast and OpenAPI render paths, plus a regression for the
RefTypeNameSubURLdouble-escape on non-ASCII branch names.This PR was written with the help of Claude Opus 4.7