Repository navigation
feat(vrowzer): report preview load failures with session identity - #59
Merged
Merged
Conversation
Each preview session now gets a load token, renewed on every mount and reload and embedded in the bootstrap document together with the host origin. While sessions are mounted, the host listens for vrowzer:preview-load-error messages and emits previewLoadError only when the token matches a session's current document, the message comes from that session's iframe, and the origin is the host's. The payload keeps only known fields with bounded lengths, and its id comes from the host's record. The bootstrap does not send reports yet.
The bootstrap now reports to the host when the preview HTML returns an error status or cannot be fetched, and when an initial script fails to load, instead of treating a script error as success. Rendering does not change: an error response body is still rendered, and the remaining scripts still run. The bootstrap is wrapped in an IIFE so that its helpers do not leak into the preview's globals, and an inline module's Blob URL is also revoked when it fails to load. The integration tests point one session's bootstrap at another URL right after mount(), so that only that session fails.
Add an Events section to the README that describes previewLoadError, its payload, and how to recover by reloading the session, and regenerate the API references for PreviewLoadErrorInfo and VrowzerEventMap.
…ynced Until a new file reaches the Workers, the preview does not answer 404 for it: the SPA fallback serves index.html with status 200. Checked in the browser by fetching a missing .ts file from the preview.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #44
Adds a
previewLoadErrorevent, so that a host can tell which preview session failed to load before its application code could start.API
VrowzerEventMapgainspreviewLoadError, with aPreviewLoadErrorInfopayload:id: the session ID, taken from the host's record of the session, never from the reportstage:'html'(fetching the preview HTML) or'script'(loading an initial script)message: always present, even when the browser gives no detailsurl,statusanderror(nameandmessage): only when knownHosts that subscribe with
on('*')also receive the new event. Existing events do not change.How it works
Each session gets a new load token on every
mount()andreload(). The bootstrapsrcdocembeds the token and the host origin.The bootstrap reports failures with
parent.postMessage():error. A scripterrorno longer counts as a successful load.The host accepts a report only when all of these hold:
Reports from replaced or removed documents are therefore ignored. The token only tells loads apart. It is not a secret, because preview code runs in the same document.
The payload keeps only known fields, with bounded string lengths.
blob:URLs of inline modules are dropped.The host listens for messages only while sessions are mounted.
Rendering does not change: an error response body is still rendered, and the remaining scripts still run. Two smaller changes in the bootstrap:
Runtime errors thrown by the application are out of scope.
Tests
index.test.ts). All 7 new tests failed before the change. They cover:srcdocand its renewal on reload;vrowzer.integration-test.ts). All 7 new tests failed before the change, because no report arrived.mount().index.html(200) through the SPA fallback, not 404. This was checked in the browser.The README has a new Events section, and the API references were regenerated.
Validated locally with:
vp run test:unit: 116 files, 1,848 testsvp run test:integration:vrowzer: 51 passed, 1 conditional skipvp run test:e2e: 46 passed, 6 existingtest.skip