-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Unify styles into single root node & support preload sandboxing #3797
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
base: dev
Are you sure you want to change the base?
Conversation
|
Essentially sandboxing makes it so that the preload script is also sandboxed and has similar access to the renderer (plus a few electron apis). So we have to move all file operations and such to the main process via IPC call. That's what this PR does |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors Vencord's CSS management system to unify all styles into a single hierarchical root node and updates the preload script to support Electron process sandboxing for future compatibility.
- Centralizes all Vencord styles under a
vencord-rootnode with three child nodes for core, managed, and user styles to maintain consistent specificity ordering - Migrates CSS loading from the preload script to IPC handlers in the main process to support sandboxed preload contexts
- Moves
classNameFactoryutility from@api/Stylesto@utils/csswith backwards compatibility maintained
Reviewed changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/api/Styles.ts | Introduces new hierarchical style root nodes and initStyles() function, exports deprecated classNameFactory for backwards compatibility |
| src/utils/css.ts | Adds classNameFactory and classNameToSelector utilities moved from Styles API |
| src/preload.ts | Refactored to use IPC for CSS loading instead of direct file system access, supporting sandboxed contexts |
| src/main/ipcMain.ts | Adds IPC handlers for renderer CSS retrieval and file watching, consolidates file watcher initialization |
| src/main/patcher.ts | Removes initIpc call as watchers now initialize via IPC request |
| src/shared/IpcEvents.ts | Adds new IPC events for CSS/JS retrieval and removes unused theme upload/delete events |
| src/VencordNative.ts | Adds stub implementations for removed theme methods, adds renderer CSS and Monaco theme getters |
| src/Vencord.ts | Updates to use new initStyles() and coreStyleRootNode |
| src/api/Themes.ts | Updates to append styles to userStyleRootNode instead of document root |
| src/components/css.ts | Removed file, functionality moved to src/api/Styles.ts |
| browser/* | Updates browser extension to pass renderer CSS URL via postMessage instead of direct insertion |
| scripts/build/buildWeb.mjs | Updates userscript to set CSS via global variable instead of direct DOM insertion |
| src/plugins/* | Updates 20+ plugin files to import classNameFactory from @utils/css instead of @api/Styles |
| src/components/* | Updates component files to import classNameFactory from @utils/css |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Unifies and organises all Vencord styles into one central root node. The main motivation behind this is that previously, styles were all over the place and it was easy to accidentally change the order in which they were inserted, which breaks specificity. That issue happened in an earlier version of this PR. Thus I decided to also reorganise.
Also refactors the preload script to support Electron process sandboxing, which heavily restricts what the preload can access.
This will only be used on Vesktop because the Discord desktop app does not support sandboxing. But once they eventually enable it, we will already be prepared :)
This is needed for Vencord/Vesktop#1206
Same PR because they are tangentially related (both refactor Vencord css logic to use IPC instead of doing it fully in the preload)