Bundler Updates: Difference between revisions

m
Grammarly
(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 ==...")
 
m (Grammarly)
Line 1: Line 1:
__NOTOC__
__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.
Discord uses a bundler to compress individual files into bigger, singular files known as chunks. This article documents major and minor changes to the bundler or its config over the years that have caused client mods to break.


== Unique CSS class names ==
== 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.
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 ==
== 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.
On July 29, 2021, Discord added a Babel rule to split every line of code into 1000 characters within the limits of syntax. At the time, no public client mods broke because none searched modules by code or used module patching.


== Webpack 5 ==
== Webpack 5 ==
On October 21, 2021, Discord updated from [https://webpack.js.org/ Webpack] 4 to 5. This introduced lazy loaded chunks and WebAssembly support.
On October 21, 2021, Discord updated from [https://webpack.js.org/ Webpack] 4 to 5. This introduced lazy-loaded chunks and WebAssembly support.


The Webpack global was renamed from <code>webpackJsonp</code> to <code>webpackChunkdiscord_app</code>.
The Webpack global was renamed from <code>webpackJsonp</code> to <code>webpackChunkdiscord_app</code>.
Line 18: Line 18:


React component display names were removed, making it harder for mods to find components.
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<ref>{{cite web|title=Ability to add displayName to all React components to prevent names from getting mangled|url=https://github.com/swc-project/swc/issues/5958}}</ref>, but they opted to not bother<ref>{{cite web|title="We might just stick with not having displayNames"|url=https://github.com/swc-project/swc/issues/5958#issuecomment-1258764673}}</ref>.
There were plans for Discord to find a way to keep display names for debugging purposes<ref>{{cite web|title=Ability to add displayName to all React components to prevent names from getting mangled|url=https://github.com/swc-project/swc/issues/5958}}</ref>, but they opted not to bother<ref>{{cite web|title="We might just stick with not having displayNames"|url=https://github.com/swc-project/swc/issues/5958#issuecomment-1258764673}}</ref>.


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 <code>default</code> becoming <code>Z</code> or <code>ZP</code>.
Module export names were mangled. Finding specific functions without searching for the function's code was even harder. There were specific patterns, such as <code>default</code> becoming <code>Z</code> or <code>ZP</code>.


== Rspack ==
== Rspack ==
Line 28: Line 28:


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


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


[https://sentry.io Sentry]'s chunk would end up overwriting the module storage, causing there to be two instances of modules but only one was ever accessible.
[https://sentry.io Sentry]'s chunk would overwrite the module storage, causing two instances of modules to exist but only one to be accessible.
<!-- should there be technical details here on how this was fixed? -->
<!-- should there be technical details here on how this was fixed? -->


Line 38: Line 38:


== Accidental Early Rspack testing on production ==
== 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.
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 <code>defaultVendors~node_modules_lodash_lodash_js~_36ba</code>.
Chunk names were not transformed into numbers, which leaked some file names. An example name would be <code>defaultVendors~node_modules_lodash_lodash_js~_36ba</code>.
Line 45: Line 45:


== Config Issues ==
== Config Issues ==
'''Config issues''' refer to minor changes to the config opposed to entire bundler updates.
'''Config issues''' refer to minor changes to the config as opposed to entire bundler updates.


=== iOS CI ===
=== iOS CI ===
[[File:iOS_Revert_Times.png|thumb|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]]
[[File:iOS_Revert_Times.png|thumb|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.
At 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 ===
=== ES version indecisiveness ===
'''[[wikipedia:ECMAScript|ECMAScript]]''' is a standard for scripting languages, namely JavaScript. It was formerly numerically versioned, but is now versioned by year.
'''[[wikipedia:ECMAScript|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.
Targeting a specific version tells the bundler what modern features need to be transpiled to compatible features supported by that version.


Line 58: Line 58:


==== December 21, 2023 ====
==== 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.
The targeted version was downgraded to what it was set to pre-Rspack (ES5?). It was reverted and unreverted several times within a 3-hour window.


[[Vendicated|Vee]] messaged Discord developer Brandon (aweary) about it and it was confirmed unintentional.
[[Vendicated|Vee]] messaged Discord developer Brandon (aweary) about it, and it was confirmed as unintentional.


==== February 28, 2024 ====
==== February 28, 2024 ====
66

edits