Skip to content
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

Document a propshaft approach to JS/CSS #2160

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jkotchoff
Copy link

Resolves #1064

Given Rails 8 has been released without transpilation or bundled JavaScript by default, this documentation update demonstrates how to use Stimulus and CSS in a ViewComponent without Webpacker.

A more terse demonstration would be possible without the view component arguments and/or less complicated Stimulus behaviour however that might be less instructive.

One of the trickier aspects of binding Stimulus controllers is often determining the correct data-controller key to use, especially when namespaces and/or multi-word component names are involved which this example makes explicit.

Approach 1 outputs a stylesheet link tag into HTML potentially several times if a ViewComponent using this technique is re-used in a page several times. Aside from that affecting the aesthetic of the rendered source, it seems like a reasonable trade-off to ensure the ViewComponent is completely self-sufficient inclusive of styling in lieu of the Encapsulating assets approach. A sidecar loaded .css (or .scss) file seems a like a logical place to look for styling.

Approach 2 demonstrates the Stimulus behaviour but not the css, that would likely involve dartsass-rails.

Resolves ViewComponent#1064

Given Rails 8 has been released without transpilation or bundled
JavaScript by default, this documentation update demonstrates how to
use Stimulus and CSS in a ViewComponent without webpacker.

A more terse demonstration would be possible without the view component
arguments and/or less complicated Stimulus behaviour however that might
be less instructive.

One of the trickier aspects of binding Stimulus controllers is often
determining the correct data-controller key to use, especially when
namespaces and/or multi-word component names are involved which this example
makes explicit.

Approach 2 demonstrates the Stimulus behaviour but not the css, that
would likely involve dartsass-rails
Copy link
Member

@joelhawksley joelhawksley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋🏻 thanks for taking this on! As we don't use this approach at GitHub, might you be able to find someone you think would be a good reviewer of this change?

@@ -10,6 +10,10 @@ nav_order: 5

## main

* Add documentation for JavaScript and CSS without webpacker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Add documentation for JavaScript and CSS without webpacker
* Add documentation for JavaScript and CSS without webpacker.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion Joel. It looks like Github uses a Catalyst approach instead of Stimulus. I have to admit, I wasn't aware of Catalyst at all and it's really interesting.

It helps explain the shadow root web component approach described in Encapsulating assets. Separately, that section appears to be unchanged since the original gem documentation was released. When I came across it, my immediate tendency was to overlook it (and the Webpacker section) given the Rails buzz around import maps / Stimulus / eliminating node atm. Perhaps there's an opportunity to mention Catalyst or contextualise Web Components a bit more in that section to help justify it's approach?

I believe it was @reeganviljoen who suggested documentation for this would be useful. I was blocked for awhile trying to figure this out in lieu of anointed documentation. Now that Rails defaults have been updated to remove Webpacker and include stimulus-rails, I suspect I'm not the only one per the activity in Issue #1064.

ViewComponent's Governance documentation suggests there are several folks with commit access to this gem. Does GitHub have a process for allocating reviewers to pull requests? I'm not very familiar with the project prior to this so wouldn't know who to approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to configure stimulus using the new rails 7 asset pipeline
2 participants