Commit ca983070 authored by Nicolas Chevobbe's avatar Nicolas Chevobbe
Browse files

Bug 1824044 - [devtools] Avoid handling the same inline script twice in pretty...

Bug 1824044 - [devtools] Avoid handling the same inline script twice in pretty printing. r=devtools-reviewers,bomsy.

While the root issue should be fixed on the server,
this patch will help reduce a frequent intermittent
and prevent showing erroneous result to users.

Differential Revision: https://phabricator.services.mozilla.com/D173660
parent 846ed0c8
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -154,10 +154,18 @@ async function prettyPrintHtmlFile({
  // for each iteration.
  const replacements = [];

  const seenLocations = new Set();

  for (const sourceInfo of actors) {
    if (!sourceInfo.sourceLength) {
    // We can get duplicate source actors representing the same inline script which will
    // cause trouble in the pretty printing here. This should be fixed on the server (see
    // Bug 1824979), but in the meantime let's not handle the same location twice so the
    // pretty printing is not impacted.
    const location = `${sourceInfo.sourceStartLine}:${sourceInfo.sourceStartColumn}`;
    if (!sourceInfo.sourceLength || seenLocations.has(location)) {
      continue;
    }
    seenLocations.add(location);
    // Here we want to get the index of the last line break before the script tag.
    // In allLineBreaks, this would be the item at (script tag line - 1)
    // Since sourceInfo.sourceStartLine is 1-based, we need to get the item at (sourceStartLine - 2)