diff --git a/runner/packages/runtime/src/monitor.ts b/runner/packages/runtime/src/monitor.ts index 57b9d672..d4cb8cf3 100644 --- a/runner/packages/runtime/src/monitor.ts +++ b/runner/packages/runtime/src/monitor.ts @@ -581,6 +581,61 @@ export const REPORTER_SOURCE = `(function () { })(); `; +/** + * The reporter as a *single physical line*, for prepending to a JS module entry. + * + * DEV-2557. Whatever we prepend to the entry shifts every position the bundler + * reports for that file, and the visitor is shown those positions verbatim. Inlining + * the reporter body cost 226 lines at the releases the Sentry events were tagged + * with, and 283 after DEV-2552 grew it — which is how a syntax error in a 70-line + * file came back as "(257:22)". One line of prefix means one line of shift. + * + * Why an indirect eval and not a separate module the entry imports: a new module + * would put a specifier the author never wrote into the graph, next to a moving entry + * path, entangled with `resolveSandboxEntry`, `sameFiles` and `stampEntry`, and would + * depend on the classic bundler evaluating an injected dependency before the entry + * body. Its failure mode is a blank preview. This form has zero graph interaction. + * + * Why `(0,eval)` and not `eval`: the indirect form evaluates in global scope, where + * the reporter's bare `window`/`parent`/`document`/`location`/`XMLHttpRequest` + * resolve, and where it leaks no bindings into the bundler's module wrapper. + * + * Why the try/catch: if `eval` is ever unavailable, that must cost monitoring on this + * path and never the demo. An entry that resolves to an HTML file (`parcel`/`static` + * with an `htmlEntry` — see `resolveSandboxEntry`) keeps the `