-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat: restructure sass configuration #154
Merged
Merged
+679
−496
Conversation
This file contains 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
mlmoravek
reviewed
Jan 21, 2025
@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
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"
.$red
is a Bulma variable and$table-sticky-header-height
is a Theme Bulma variable. Either will cause the error. Interestingly if you only pass$primary
the 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$example
is 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@use
statement that@use
can be shifted to an invalid position relative to other code. Typically this breakssrc/assets/scss/components/utils/_variables.scss
where 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.!default
variables have been collected in two files mirroring the internal structure of Bulma._initial-defaults.scss
collects all variables which do not reference Bulma. These variables have been placed before the main Bulma@use
._derrived-defaults.scss
collects all variables which do reference Bulma. These variables have been placed after the main Bulma@use
.@use
has been moved tobulma-build.scss
so its order can be easily controlled.src/assets/scss/components/utils/_variables.scss
has 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.scss
has been added as the entrypoint for the separate bulma use-case.bulma.scss
is 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.ts
to the newbuild.ts
. This solves an issue where the style import intheme.ts
was 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.scss
andmain-separated.scss
to represent the two use cases so we can easily test either one. Combined is the default.pack:lib
npm command and gitignore for the packed tarball. Very handy if you want to test in an external codebase.