Bundler Updates

Revision as of 02:41, 14 March 2024 by Cynosphere (talk | contribs) (Created page with "__NOTOC__ Discord uses a bundler to compact down individual files into bigger singular files, known as chunks. This article serves to document major and minor changes to the bundler or its config over the years that have caused client mods to break. == Unique CSS class names == Sometime in 2017 or 2018, Discord introduced a bundler plugin that made CSS class names unique by adding a random 6 character string at the end of the class. == 1000 character line splitting ==...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Discord uses a bundler to compact down individual files into bigger singular files, known as chunks. This article serves to document major and minor changes to the bundler or its config over the years that have caused client mods to break.

Unique CSS class names

Sometime in 2017 or 2018, Discord introduced a bundler plugin that made CSS class names unique by adding a random 6 character string at the end of the class.

1000 character line splitting

On July 29, 2021, Discord added a Babel rule to split every line of code to 1000 characters within limits of syntax. No public client mods at the time broke because none were searching modules by code or using module patching.

Webpack 5

On October 21, 2021, Discord updated from Webpack 4 to 5. This introduced lazy loaded chunks and WebAssembly support.

The Webpack global was renamed from webpackJsonp to webpackChunkdiscord_app. Entrypoint modules were changed from an array of module IDs to a function with Webpack's require function as the only argument.

SWC

On September 26, 2022, Discord switched from Webpack to SWC. This is considered the great cataclysmic event that killed off almost every client mod.

React component display names were removed, making it harder for mods to find components. There were plans for Discord to find a way to keep display names for debugging purposes[1], but they opted to not bother[2].

Module export names were mangled. It was even harder to find specific functions without searching for the code of the function. There were specific patterns such as default becoming Z or ZP.

Rspack

On October 26, 2023, Discord switched from SWC to Rspack. While not as cataclysmic, it wasn't without issues.

Module export names return. This caused parts of mods broken by SWC to work in some capacity, excluding React component display names.

Every theme was now broken as Rspack's unique class name plugin uses _ or __ as the separator between the name and the random string. In addition, every stylesheet was now loaded in the body instead of the head, forcing client mods to put their stylesheets in document.documentElement for highest priority.

Upwards of 100 chunk files are initially loaded instead of 4.

Sentry's chunk would end up overwriting the module storage, causing there to be two instances of modules but only one was ever accessible.

The chunk loader chunk loads later than expected, forcing mods that use module patching to disregard further calls to binding webpackChunkdiscord_app.push.

Accidental Early Rspack testing on production

On September 29, 2023, a build on Canary was released that broke everything. It was not known at the time this was Rspack. It was using a non-production ready config.

Chunk names were not transformed into numbers, which leaked some file names. An example name would be defaultVendors~node_modules_lodash_lodash_js~_36ba.

Script tags had the defer property set, causing loading race conditions in some mods.

Config Issues

Config issues refer to minor changes to the config opposed to entire bundler updates.

iOS CI

 
A message of a (Discord?) moderator (in the TestFlight server?) confirming that iOS CI builds being pushed to Canary weren't intentional and had to be reverted. Also confirming Discord's build times at the time

During the beginning of August 2021, Discord had an older CI for iOS builds that would push builds to Canary that would have to be reverted.

ES version indecisiveness

ECMAScript is a standard for scripting languages, namely JavaScript. It was formerly numerically versioned, but is now versioned by year. Targeting a specific version tells the bundler what modern features need to be transpiled to compatible features supported by that version.

Changing this version breaks mods that use module patching.

December 21, 2023

The targeted version was downgraded to what it was set to pre-Rspack (ES5?). It was reverted and unreverted a handful of times within a 3 hour window.

Vee messaged Discord developer Brandon (aweary) about it and it was confirmed unintentional.

February 28, 2024

The targeted version was bumped to ES 2020 or newer. It was reverted within 24 hours.

  1. "Ability to add displayName to all React components to prevent names from getting mangled".
  2. ""We might just stick with not having displayNames"".