Commit 300b018
fix(core): Avoid parse-time SyntaxError on Safari <16.4 in postgresjs (#20498)
Bandaid fix for #20433. Constructs the negative-lookbehind regex via
`new RegExp(...)` instead of a regex literal, so it is evaluated at
runtime rather than at parse time.
[Safari <16.4 does not support lookbehind
assertions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookbehind_assertion)
as a literal, this causes a parse-time `SyntaxError` that kills the
entire script.
As a constructor call with `new RegExp`, parsing succeeds;. Correctness
in Safari doesn't matter here, we just don't want the file to fail to
parse and it would never execute anyways.
The deeper issue is that server-only code from `@sentry/core`
(postgresjs, express, trpc, mcp-server, the AI instrumentations, etc.)
can end up in browser bundles because it seems like some bundlers can't
tree-shake it out of the core barrel. We should be more disciplined
about what the main `@sentry/core` entry re-exports so apps stop
shipping server code that never executes.
I managed to reproduce this setup in a webpack with CJS app and noticed
it didn't tree-shake the postgres integration. Vite seems to do it
correctly.
Bringing this up next week, but we should not rely on tree-shaking to
eliminate code-paths.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 786fdf7 commit 300b018
1 file changed
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
| 345 | + | |
| 346 | + | |
345 | 347 | | |
346 | 348 | | |
347 | 349 | | |
| |||
356 | 358 | | |
357 | 359 | | |
358 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
359 | 368 | | |
360 | 369 | | |
361 | 370 | | |
| |||
378 | 387 | | |
379 | 388 | | |
380 | 389 | | |
381 | | - | |
| 390 | + | |
382 | 391 | | |
383 | 392 | | |
384 | 393 | | |
| |||
0 commit comments