-
Notifications
You must be signed in to change notification settings - Fork 436
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
Replace stylesheets #1180
base: main
Are you sure you want to change the base?
Replace stylesheets #1180
Conversation
fbd042f
to
567b55a
Compare
567b55a
to
7720f22
Compare
@gooroodev, can you review? |
Please double-check what I found in the pull request:
Summary of Proposed Changes
Identified Issues
Issue 1: Commented out code should be removed if not neededDetailsCommented out code can clutter the codebase and reduce readability. If the code is not needed, it should be removed. This occurs in the following lines:
FixRemove the commented out code. // Remove the following commented out code:
// if (this.willRender) {
// this.removeUnusedDynamicStylesheetElements()
// }
// async copyNewHeadStylesheetElements() {
// const loadingElements = []
//
// for (const element of this.newHeadStylesheetElements) {
// loadingElements.push(waitForLoad(element))
//
// document.head.appendChild(element)
// }
//
// await Promise.all(loadingElements)
// }
// removeUnusedDynamicStylesheetElements() {
// for (const element of this.unusedDynamicStylesheetElements) {
// document.head.removeChild(element)
// }
// } Issue 2: Console logs should be removed or replaced with proper logging mechanismDetailsConsole logs are useful for debugging but should be removed or replaced with a proper logging mechanism in production code. This occurs in the following lines:
FixRemove the console logs or replace them with a proper logging mechanism. // Example of removing console logs:
// console.log(`Skipping ${newHref}`)
// console.log(`Updating ${oldElement.getAttribute("href")} to ${newHref}`)
// console.log(`Appending ${newHref} after`, lastStylesheetElement)
// console.log(`Removing ${element.getAttribute("href")}`)
// console.log(`Converting preload ${element.getAttribute("href")}`) General ReviewThe proposed changes introduce new functionality to handle dynamic stylesheet elements more effectively, maintaining their order and removing old stylesheets when necessary. The code quality is generally good, but there are some areas for improvement:
Overall, the changes are well-structured and improve the handling of dynamic stylesheets. -- |
Nothing about this is ready to review other than the technique. |
For a while our application has had this method of replacing stylesheets that maintains the order of stylesheets as best as it can and replaces stylesheets in place if only their digest has changed. This is more sophisticated than what was there originally, but you'll notice that if you attempt to use the existing
fixtures/stylesheets/left.html
andright.html
interactively that it doesn't work more than once. Turbo seems to hang and then refresh the page. With this method, not only does that work, but the additional fixture I put in place that ensures there's minimal to no flicker or ordering issues works as well.I'm opening this as a draft to see if there is interest in this and/or concerns. I'm happy to clean it up if it seems like something you'd want to move forward with, which would allow us to remove our custom code from our codebase.
Thank you for the consideration.