-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(Webpack): Immediate finds using waitFor and complete rewrite of module patching #2409
base: dev
Are you sure you want to change the base?
Conversation
Documented the changes |
6860ec6
to
8d31330
Compare
49fcfd7
to
511ec1b
Compare
41a1732
to
09f8944
Compare
1283494
to
d40dfc3
Compare
9a1a7b3
to
329bc68
Compare
@CodiumAI-Agent /review |
@CodiumAI-Agent /improve |
PR Code Suggestions ✨Latest suggestions up to c183018
Previous suggestionsSuggestions
|
d936604
to
090a3bc
Compare
c4c92ed
to
c50208b
Compare
A complete refactor of the Vencord Webpack API. This rewrites how Webpack finds and module patches are done.
Changes to Webpack finding:
Completely deprecates the
lazy
way that we currently do Webpack finds. Instead, now the default will be a unified way which is a combination of the plaincacheFind
for already loaded modules, and usage ofwaitFor
for when modules were not yet loaded.The way this works is:
waitFor
alternative. By using waitFor, everytime a new module is loaded, Vencord will check if that module matches any of the finds requested, and if it does, it sets the result of that find to the module. This avoids having to iterate through the module cache for every find.By having the unified way, we no longer need a
lazy
alternative of the methods, so the following changes to the API occurred:find
->cacheFind
find
(wrapper aroundwaitFor
andcacheFind
)findLazy
->find
(wrapper)findByProps
,findByPropsLazy
->findByProps
findByCode
,findByCodeLazy
->findByCode
findStore
,findStoreLazy
->findStore
findComponent
,findComponentLazy
->findComponent
findExportedComponent
,findExportedComponentLazy
->findExportedComponent
findComponentByCode
,findComponentByCodeLazy
->findComponentByCode
mapMangledModule
,mapMangledModuleLazy
->mapMangledModule
The following were added for additional filters and refactors purposes:
findProp
-> Useful as an alternative to a top level destructure. See it's JSDoc documentation for more information.findComponentByFields
-> Used for finding a class component using its prototype fieldsfindByFactoryCode
-> Use for finding all the exports of a module using its factory codeThe following were changed for more appropriate names:
findAll
->cacheFindAll
findBulk
->cacheFindBulk
findModuleId
->cacheFindModuleId
The following were changed for less weird names:
proxyLazyWebpack
->webpackDependantLazy
LazyComponentWebpack
->webpackDependantLazyComponent
findModuleFactory
now uses the same tactic as the normal finds, and its old version using cache is nowcacheFindModuleFactory
Warning
Destructuring Webpack finds at top level is now deprecated. It used a very hacky tricky which turns out to not always have the expected result (pshhhh Firefox)
mapMangledModule is the only exception for this
Consider switching to mapMangledModule or findProp
Important additions:
Additional:
Important
This change is fully backwards compatible for now. Old methods were kept and just point to the new APIs and top level destructuring is kept with a warning.
The plan is to remove the deprecated methods/features in the future.
Changes to Webpack module patching:
Centralizes Webpack patching around a single thing: Patching the module factories object of the WebpackRequire (wreq.m). This wraps the modules object with a proxy to intercept the addition of new modules, and allow us to decide what to do with them.
A new internal setting was added, eagerPatches, and it decides what to do with the newly added modules. With it enabled, we patch the factories as soon as they are set, and with it disabled we only patch them once they are accessed for the first time (default).
For correctly handling patching, because of multiple WebpackInstances, and to allow for patching factories only when they are accessed, our proxy defines getters and setters for each module factory added, instead of doing a simple Reflect.set on the module factories object.
Additionally, these were done: