-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add sass support via sass-embedded #1911
Conversation
Not sure what was causing the glitch during bundle install in the CI test, I triggered the same CI test in my fork and everything was fine: https://github.com/ntkme/sinatra/actions/runs/4430689681/jobs/7772740876 |
Saw that, super strange (but interesting?). I can trigger re-run here. EDIT: Link to the failed job https://github.com/sinatra/sinatra/actions/runs/4429712174/jobs/7770993289 |
Here is my guess: In a good run:
In a failed run:
I suspect this different order is causing some trouble. - rubygems Side note: In setup-ruby, if ruby 2.x is picked, it will update rubygems/bundler to latest, but if ruby 3.x is picked, it uses whatever rubygems/bundler version comes with that ruby version. - So in the end, ruby 3.0 is the unlucky one that ended up with the most outdated rubygems/bundler... |
I was able to reproduce this with a branch that has psych 5.1.0 in the GitHub Action's cache and then attempt to install sass-embedded. I also found two ways to fix it:
|
Thanks for investigating that @ntkme FYI ⬆️ to @eregon and @deivid-rodriguez, maybe something good to be aware of if you aren't already |
Minimal reproduction: The default versions of rubygems + psych work fine: docker run --rm -i --entrypoint /bin/sh ruby:3.0.5 <<'EOF'
gem install sass-embedded --platform ruby
EOF The updated psych breaks default rubygems: docker run --rm -i --entrypoint /bin/sh ruby:3.0.5 <<'EOF'
gem install psych
gem install sass-embedded --platform ruby
EOF If both are updated, then it works again: docker run --rm -i --entrypoint /bin/sh ruby:3.0.5 <<'EOF'
gem update --system
gem install psych
gem install sass-embedded --platform ruby
EOF |
@dentarg The issue turns out to be related to this: rubygems/rubygems@189f658. Edit: The commit above is related, but the root cause is slightly different:
However, this difference is not because the code is different, in fact the code is the same. The problem is "-I#{File.expand_path("../..", __dir__)}" What leads to the problem is the way ruby loads native extension. With two copies of psych installed (one system copy, one user copy).
So upgrade rubygems is really just a workaround. The real fix is: rubygems/rubygems#6490 |
The rubygems bug fix for |
As far as I know, there is one project that was using this feature and might be interested in this PR: gma/nesta@91c5725 cc @gma |
@@ -862,7 +876,10 @@ def render(engine, data, options = {}, locals = {}, &block) | |||
catch(:layout_missing) { return render(layout_engine, layout, options, locals) { output } } | |||
end | |||
|
|||
output.extend(ContentTyped).content_type = content_type if content_type | |||
if content_type | |||
output = +output |
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.
Was this a problem before, that this string was frozen?
Maybe we should commit this change separately? With a test for it?
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.
This is due to google-protobuf gem decodes the output as frozen string. There is a performance concern on eagerly unfreezing when not necessary. Therefore, sass-embedded returns the css output as frozen string as is, for which dependencies need to unfrozen the string as needed.
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.
Can we only unfreeze when sass-embedded is used? Can we at least add a comment to the code with the above information?
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.
I added a comment.
As for the +string
method:
Returns self if self is not frozen.
Otherwise. returns self.dup, which is not frozen.
I did a microbenchmark on different ways to write this, and output = +output
is the most performant one:
user system total real
s.freeze; s = s.dup if s.frozen?; 1.553977 0.006994 1.560971 ( 1.561001)
s.freeze; s = +s if s.frozen?; 0.919195 0.002047 0.921242 ( 0.921248)
s.freeze; s = +s; 0.763196 0.001567 0.764763 ( 0.764776)
Looks good to me, I think we want this. @sinatra/sinatras-helpers any comments? |
@dentarg LGTM! |
I guess I was wrong on rubygems version for ruby 3.0.6. It still need a rubygems update. |
Can you add that for the Ruby 3.0 job? We can remove that if there ever is a Ruby 3.0.x release with RubyGems that includes rubygems/rubygems#6490 |
Sass support was removed from Sinatra 3 due to the `ruby-sass` gem becoming unmaintained[1]. Support has since been re-added[2], backed by the modern `sass-embedded` gem, but this hasn't landed in a Sinatra release yet. Until that happens, let's shim the rendering method. [1] sinatra/sinatra#1768 [2] sinatra/sinatra#1911
This PR adds support for sass back via sass-embedded (backed by currently maintained official dart-sass-embedded).
It requires
tilt>=2.0.11
, which is the first version that introduced support for sass-embedded.