feat: restructure sass configuration#154
Merged
mlmoravek merged 46 commits intooruga-ui:mainfrom Mar 10, 2025
Merged
Conversation
mlmoravek
reviewed
Jan 21, 2025
Contributor
Author
|
@mlmoravek have another look at this PR when you get a sec. I refactored how the component defaults work to use the structure you proposed. I think this works a lot better now. I've created oruga-ui/oruga#1172 to update the docs scripting to handle the changes and tested it with new and old code. Everything appears to be working well. |
mlmoravek
reviewed
Jan 31, 2025
mlmoravek
reviewed
Feb 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #150
The Problem
Theme Bulma works just fine until you try to configure the SCSS. This will work fine:
but if you add a config value like this
you'll get an error
[sass] This module was already loaded, so it can't be configured using "with".$redis a Bulma variable and$table-sticky-header-heightis a Theme Bulma variable. Either will cause the error. Interestingly if you only pass$primarythe error will not occur.Confusing, huh? The error complains about the order of the code, but the order of the code isn't changing, we're only passing config values. How can this even be possible? The answer appears to be hoisting. I can't find any sass documentation for this but it seems that when you have a defaulted sass variable like
$example: #f00 !default;which is referenced bywith (...)syntax, the file which contains$exampleis hoisted to the top of the pile of sass files being processed. This isn't always a problem but if the hoisted file references Bulma with an@usestatement that@usecan be shifted to an invalid position relative to other code. Typically this breakssrc/assets/scss/components/utils/_variables.scsswhere the theme configures Bulma to pass secondary/custom color.This problem is compounded by the fact that Theme Bulma needs to support two use cases: using Bulma as part of the theme or separate from it. The two code pathways can break differently in some situations.
The Solution
The solution is reorganizing Theme Bulma code to ensure that the primary bulma
@use with (...)statement always comes first.!defaultvariables have been collected in two files mirroring the internal structure of Bulma._initial-defaults.scsscollects all variables which do not reference Bulma. These variables have been placed before the main Bulma@use._derrived-defaults.scsscollects all variables which do reference Bulma. These variables have been placed after the main Bulma@use.@usehas been moved tobulma-build.scssso its order can be easily controlled.src/assets/scss/components/utils/_variables.scsshas been rewritten. Its purpose is the same, allowing you to pull Bulma variables into any theme component that needs them, but it is now hardened against hoisting errors and able to provide ALL variables from Bulma and the theme rather than just Bulma's derived variables. This is important because..._variables.scss. This provides a consistent pathway to variables where order can be preserved, even when the theme is being used separately from Bulma. References to Bulma mixins etc have been preserved as-is, they never error.component-only-build.scsshas been added as the entrypoint for the separate bulma use-case.bulma.scssis unchanged but is now intended to be used internally as an entrypoint for component sass.I also made some secondary fixes to the theme development environment to make dev and testing easier.
src/plugin/theme.tsto the newbuild.ts. This solves an issue where the style import intheme.tswas creating duplicate css based on the default values for color etc, making it impossible to see the changes made in the scss files.main-combined.scssandmain-separated.scssto represent the two use cases so we can easily test either one. Combined is the default.pack:libnpm command and gitignore for the packed tarball. Very handy if you want to test in an external codebase.