Conversation
This moves preview rendering to an iframe with a document loaded cross-origin as a source. This enforces cross-origin separation and gives the preview window it's own localstorage, isolated from the parent. Content is injected into the doc via `postMessage`.
This prevents the project HTML etc. being sent before the renderer has initialised, which was resulting in the the message being missed and the Run button appearing to do nothing when initially clicked.
…o 1264_cross-origin-html-preview
These tests no longer work, and I'm not sure whether it's possible to use RTL to read the contents of the new inner iframe. There are duplicate Cypress tests for many of these, and Cypress is a lot easier to work with in this case so I will make the changes there.
The docs reccommend against this, because it makes utils less flexible. I'm also trying to deal with some flakiness here, so we'll see if this helps.
4c756ab to
8ccd3e6
Compare
These are not currently working on CI. We may move these to the E2E test repo.
91a299c to
6a4f54e
Compare
This means the embedded mode preview has the full height of the content as before.
There was a problem hiding this comment.
Pull request overview
This pull request restructures the HTML preview rendering to use a cross-origin iframe approach instead of the previous blob URL method. The renderer is moved to a separate application that loads at HTML_RENDERER_URL, and content is communicated via postMessage. This enforces security isolation and gives the preview window its own isolated localStorage.
Changes:
- Create a new webpack configuration and entry point for the HTML renderer as a separate application
- Refactor HtmlRunner to use postMessage instead of directly manipulating blob URLs in the iframe
- Create new HtmlRenderer component to handle HTML rendering and message passing
- Move iframe origin validation logic to a shared utility module
- Remove legacy test cases that were specific to the old blob URL approach
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| webpack.html-renderer.config.js | New webpack configuration for building the HTML renderer as a separate bundle |
| src/html-renderer.jsx | New entry point for the HTML renderer application |
| src/utils/iframeUtils.js | New utility module for iframe security validation and message constants |
| src/components/Editor/Runners/HtmlRunner/HtmlRenderer.jsx | New component that handles HTML rendering and cross-origin communication |
| src/components/Editor/Runners/HtmlRunner/HtmlRunner.jsx | Refactored to use postMessage instead of blob URLs |
| src/components/ScratchEditor/ScratchIntegrationHOC.jsx | Updated to use shared iframe utility function |
| src/components/Editor/Runners/HtmlRunner/HtmlRunner.test.js | Removed tests specific to old blob URL approach |
| .github/workflows/deploy.yml | Updated deployment pipeline to build and deploy HTML renderer separately |
| package.json | Added build and start scripts for HTML renderer |
| Other supporting files | Added HTML template, styles, and configuration files |
Comments suppressed due to low confidence (1)
cypress/e2e/spec-html.cy.js:1
- All end-to-end Cypress tests for HTML functionality have been removed from
spec-html.cy.js, including critical tests for localStorage blocking (authKey, OIDC keys), permission validation for external links, and internal link navigation. These behaviors should be covered by E2E tests to ensure the preview functionality works correctly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I was thinking about the seperate webpack config and tasks to run and build. Is the intention to have the iframe deployed and served from the same bucket as editor-ui? |
This moves preview rendering to an iframe with a document loaded cross-origin as a source. This enforces cross-origin separation and gives the preview window it's own localstorage, isolated from the parent. Content is injected into the doc via
postMessage().Most of the logic in the new
HtmlRenderercomponent (besides message handling) has been moved over fromHtmlRunner.