How One Line of JavaScript Took My Entire Website Down for 11 Hours
How a single JavaScript constant caused an 11-hour production outage, exposed a hidden Vite chunk dependency, and prompted two new deployment safeguards.
Candidate Falcon, a practice site for hiring assessments, experienced an 11-hour outage in early November due to a single line of JavaScript code. The issue arose when a release added two new interview types, causing every page to go blank. The login form failed to render, buttons malfunctioned, and the console displayed an error: ReferenceError: Cannot access 'ko' before initialization.
Despite deploy checks indicating everything was fine, the site remained inaccessible for nearly a day. To prevent this from happening again, the development team added two checks. The main chunk in the app, built with Vite and Rollup, was split into manualChunks based on sections of the site. The 'one-way' chunk contained modules related to interview types, while other chunks handled different features.
The problematic line of code imported a shared constant, VIDEO_PROVIDER_IDS, into the 'one-way' chunk. When the browser loaded the bundle, it evaluated the chunks in a specific order. Since the 'one-way' chunk was already in progress when the main chunk started, it ran its code immediately, leading to a ReferenceError as the 'ko' binding was accessed before its declaration.
The fix involved reading the value when needed rather than when the module loaded. A test was added to detect this pattern, ensuring module-level constants were not copied from imported values. Additionally, the team now checks the live site in a browser after every deploy, reading the console for potential issues. These measures were implemented to avoid similar outages in the future.
Rewritten by urgent.news; may contain errors โ check the original.
Source: hackernoon.com
Read the original at hackernoon.com โ
More from HackerNoon on urgent.news
Report a problem with this story
Get the day's news by email. Daily, weekly or monthly. Sign up