fix: defer UserInteractionInstrumentation enable() past field init to fix _eventNames TypeError #SUPERLOG - #416
Open
superlog-app[bot] wants to merge 1 commit into
Conversation
… fix _eventNames TypeError #SUPERLOG Delivery-Id: 1873234cdfe0ad22126e363649481acbe9904f45693c6c4a4c1a9ac3cecae0eb Delivery-Base: main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every user click on the production web app was throwing
TypeError: this._eventNames is undefinedinside the Zone.jsrunTaskpatch, generating 207+ noisybrowser.exceptionspans in ~46 seconds. The globalwindow.errorhandler added in #414 surfaced this pre-existing silent failure.Root Cause
UserInteractionInstrumentation@0.59.0has a class field initialization ordering bug when bundled by Vite/esbuild.InstrumentationBase.constructorcallsthis.enable()insidesuper(), before the derived class's own field initializers run. Vite transforms_eventNames;(class field, no initializer) into an explicitI(this,"_eventNames")statement placed aftersuper()but before the constructor body assignmentthis._eventNames = new Set(['click']).Confirmed in the production bundle (
index-CS7X72oT.js:15:79301):When Zone.js tasks fire asynchronously (React dynamic-import Promise callbacks, click events) between those two lines,
_allowEventNamecallsthis._eventNames.has(eventName)and throws. The error propagates towindow.onerror, the new handler captures it as abrowser.exceptionspan.Fix
Pass
{ enabled: false }to the constructor soenable()is not called duringsuper(). Callenable()explicitly after the constructor returns, at which point_eventNames = new Set(['click'])is guaranteed. Zone.js is then patched with the correct state.registerInstrumentationscallsc.getConfig().enabled || c.enable()— sinceenabled: false, it would callenable()again, but_isEnabledis alreadytruefrom our explicit call, so it returns immediately with no double-patching.Impact
Stops 207+ false-positive
browser.exceptionspans per session on the/route. Click-to-fetch trace correlation continues to work correctly after this fix.Fixes incident f47626e5-9d9d-4ef7-aed5-cdc22414fce1 (chalky-lynx).
Was this PR helpful? Leave feedback — goes straight to the Superlog team.
Summary by cubic
Defer enabling of
UserInteractionInstrumentationuntil after its fields are initialized to prevent_eventNamesTypeError. This stops noisybrowser.exceptionspans and keeps click instrumentation working.UserInteractionInstrumentationwith{ enabled: false }and call.enable()after construction, avoidingInstrumentationBasecallingenable()insuper()._eventNamesis set beforeZone.jspatches run, fixing theVite/esbuildclass field order issue and removing 200+ exception spans per session.Written for commit ad67b66. Summary will update on new commits.