Skip to content
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 #2409

Open
wants to merge 178 commits into
base: dev
Choose a base branch
from
Open

Conversation

Nuckyz
Copy link
Collaborator

@Nuckyz Nuckyz commented May 3, 2024

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 plain cacheFind for already loaded modules, and usage of waitFor for when modules were not yet loaded.

The way this works is:

  • If you use the find methods in the top level, you will leverage the performance gain of using the 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 using the waitFor alternative, the result of calling the find methods is a Proxy, which has a value inside which points to the module. When the module is found that value is set, and now the Proxy acts as the module found.

Trying to access a Proxy value before the module value is set will cause an error, which shows the filter that failed. This allows users to post better logs for us.

  • However, if you don't use in the top level, you will mostly likely just find the module using cacheFind, which does need to iterate through the module cache. But of course, if the module is not in the cache it will still register a waitFor, to find the module in case it is loaded later.

By having the unified way, we no longer need a lazy alternative of the methods, so the following changes to the API occurred:

  • Old find -> cacheFind
  • New find (wrapper around waitFor and cacheFind)
  • findLazy -> find (the wrapper)
  • findByProps, findByPropsLazy -> findByProps
  • findByCode, findByCodeLazy -> findByCode
  • findStore, findStoreLazy -> findStore
  • findComponent, findComponentLazy -> findComponent
  • findExportedComponent, findExportedComponentLazy -> findExportedComponent
  • findComponentByCode, findComponentByCodeLazy -> findComponentByCode

The following were changed for more appropriate names:

  • findAll -> cacheFindAll
  • findBulk -> cacheFindBulk

The following were changed for less weird names:

  • proxyLazyWebpack -> webpackDependantLazy
  • LazyComponentWebpack -> webpackDependantLazyComponent

The following were not changed:

  • findModuleId
  • findModuleFactory
  • ConsoleShortcuts preserved the same because it uses cacheFindAll and filters internally, so it doesn't rely on the way the old methods worked.

Additional:

  • Lots of cleanups related to the main Webpack finding API, lazy stuff and other misc things
  • Make reporter take advantage of the way the new finds work, so it no longer has to re-search everything
  • As stated before, better error for modules not found.

Warning

These are the files that the most changes were introduced: webpack.tsx, lazy.ts, lazyReact.tsx, proxyInner.ts, generateReport.ts and the commons in webpack
The rest is mainly just changing to use the new methods instead of the deprecated ones

Important

This change is fully backwards compatible for now, as the old methods were kept and just point to the new APIs now.
The plan is to remove them in the future.

@Nuckyz
Copy link
Collaborator Author

Nuckyz commented May 3, 2024

Documented the changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants