Commit 2233d721 authored by Robert Knight's avatar Robert Knight

Limit line length in minified JS bundles

Limit the line length in minified bundles to make them easier to examine in
various tools which don't like very long source lines, and also mitigate an
issue with stack traces in Firefox.

Firefox stack traces report column numbers in Unicode code points whereas Sentry
expects UTF-16 code units. If the input source contains Unicode characters which
require multiple UTF-16 code units to represent then processed stack traces in
Firefox will point to the wrong location.

One of our dependencies (Showdown) contains a long string of emojis, which
require multiple UTF-16 units to represent, and Terser by default tries to
compress the code into as few lines as possible. The combined result of this is
that stack traces from Firefox could end up being resolved to a location far
from what is expected.

Though it is not a complete fix for the issue, limiting the length of lines
effectively mitigates this problem as only code nearby (on the same line as)
these characters in the output is affected.

I did also try Terser's `ascii_only` output option, but that increased the
bundle size by 2% and has more potential for unexpected consequences elsewhere.
parent 52da1f28
...@@ -15,10 +15,17 @@ if (isProd) { ...@@ -15,10 +15,17 @@ if (isProd) {
prodPlugins.push( prodPlugins.push(
terser({ terser({
format: { format: {
// Strip *all* comments from minified output. This works around an // Strip *all* comments from minified output. This works around an issue
// issue with column numbers in stack traces in Safari. // with column numbers in stack traces in Safari. See
// See https://bugs.webkit.org/show_bug.cgi?id=221548. // https://bugs.webkit.org/show_bug.cgi?id=221548 and
// https://github.com/hypothesis/client/issues/4045.
comments: false, comments: false,
// Limit length of lines in output. This makes the minfied output easier
// to examine in tools that struggle with long lines and limits the
// impact of an issue with stack trace column numbers in Firefox.
// See https://github.com/hypothesis/client/issues/4045.
max_line_len: 1024,
}, },
}) })
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment