Skip to content

Stop terser from negating the coach IIFE's return value#177

Merged
soulgalore merged 1 commit into
mainfrom
fix-merge-falsy-dom-result
May 18, 2026
Merged

Stop terser from negating the coach IIFE's return value#177
soulgalore merged 1 commit into
mainfrom
fix-merge-falsy-dom-result

Conversation

@soulgalore
Copy link
Copy Markdown
Member

The minified coach script is invoked in the browser via Selenium's
executeScript by way of return ${script}, so the outer IIFE's return
value IS the contract — sitespeed.io reads it back as
browserScriptsData.coach.coachAdvice and expects an object with the
collected advice, errors and version.

Terser's negate_iife compress option rewrites a top-level
(function(){…})() as !function(){…}() to shave a byte. That turned
the advice object into false on the wire. The bug was latent: an old
--compresss typo meant compression never ran, so the negation never
happened. Once that typo was fixed (dd178ab) compression kicked in and
sitespeed.io started seeing coachAdvice === false, then crashing the
DOM/HAR merge and the html templates that assume DOM data exists.

Disable negate_iife in the terser invocation so the IIFE keeps its
return value.

Co-authored-by: Claude Opus 4.7 (1M context) noreply@anthropic.com

  The minified coach script is invoked in the browser via Selenium's
  executeScript by way of return ${script}, so the outer IIFE's return
  value IS the contract — sitespeed.io reads it back as
  browserScriptsData.coach.coachAdvice and expects an object with the
  collected advice, errors and version.

  Terser's negate_iife compress option rewrites a top-level
  (function(){…})() as !function(){…}() to shave a byte. That turned
  the advice object into false on the wire. The bug was latent: an old
  --compresss typo meant compression never ran, so the negation never
  happened. Once that typo was fixed (dd178ab) compression kicked in and
  sitespeed.io started seeing coachAdvice === false, then crashing the
  DOM/HAR merge and the html templates that assume DOM data exists.

  Disable negate_iife in the terser invocation so the IIFE keeps its
  return value.

  Co-authored-by: Claude Opus 4.7 (1M context) noreply@anthropic.com
@soulgalore soulgalore merged commit 9e63bfb into main May 18, 2026
3 checks passed
@soulgalore soulgalore deleted the fix-merge-falsy-dom-result branch May 18, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant