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

Automate/simplify setup steps when consuming a Blazor component library #49880

Open
danroth27 opened this issue Aug 4, 2023 · 5 comments
Open
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one Pillar: New Blazor Priority:1 Work that is critical for the release, but we could probably ship without
Milestone

Comments

@danroth27
Copy link
Member

All of the major Blazor component libraries require multiple steps in order to setup their libraries in a Blazor app. Often these steps include:

  • Added JavaScript files
  • Linking to CSS style sheets
  • Registering services in DI
  • Adding infrastructure components that enable cross-cutting features
  • Adding using directives for namespaces

Are there perhaps some patterns here that we can enable component library authors to automate so that it's easier to consume Blazor components? Are there common framework abstractions we should be adding to Blazor so that component libraries can reuse them and better compose with each other? Is there additional guidance we should provide to help component library authors make their libraries easier to consume?

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Aug 4, 2023
@guardrex
Copy link
Contributor

guardrex commented Aug 5, 2023

Cross-link (possibly a dup of): #47624

@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Aug 7, 2023
@mkArtakMSFT mkArtakMSFT added this to the .NET 9 Planning milestone Aug 7, 2023
@KristofferStrube
Copy link
Contributor

Just wanted to note that most libraries already have the first part (adding JavaScript files) covered by using modules instead and importing these as IJSObjectReferences from code as a part of the service registration.

Something that would be cool to have is a parallel to this but for CSS. Ideally, this should enable dynamically adding CSS style sheets. Sadly there isn't an agreed-upon way to load CSS style sheets dynamically. But if we were to think big, I could imagine one of two solutions.

  1. Always load the compiled CSS file (the one generated when using scoped CSS files) when a project references a razor class library that has one.
  2. Have some way to keep the scoped CSS files separate when packaging the razor class library and then compile the scoped CSS of each component that is used directly in a project into the compiled CSS file for that project as if the component was a first-class-citizen in that project. Then the only problem would be that some components are created dynamically, meaning we can't make any analysis on them when compiling. I guess there are many ways to get around that, i.e. defining a list of components to import scoped CSS for in the package reference for that library or something similar (not sure what the best approach would be).

This is just me starting spit-balling a bit to start the discussion as I'm really interested in how we can make the consumption of razor class libraries easier for the consumers.

@ghost
Copy link

ghost commented Jan 3, 2024

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@SteveSandersonMS
Copy link
Member

We think this might be viable to make the RCL template a bit more structured to show examples of auto-including JS, CSS, and using some IServiceCollection extension for registering DI services and cascading values.

We'd also like to improve docs to encourage this.

@SteveSandersonMS SteveSandersonMS added the Priority:1 Work that is critical for the release, but we could probably ship without label Jan 18, 2024
@SteveSandersonMS SteveSandersonMS changed the title Improve the user experience of consuming Blazor component libraries Automation of setup steps when consuming a Blazor component library Jan 24, 2024
@SteveSandersonMS SteveSandersonMS changed the title Automation of setup steps when consuming a Blazor component library Automate/simplify setup steps when consuming a Blazor component library Jan 24, 2024
@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 10 Planning, Backlog Nov 4, 2024
@pkostaki
Copy link

pkostaki commented Nov 14, 2024

Are there any plans to enable the automatic import of arbitrary CSS files (which are not part of the components and cannot currently be imported automatically by vs tooling), from the RCL into the project?
(check created feature request for details)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one Pillar: New Blazor Priority:1 Work that is critical for the release, but we could probably ship without
Projects
None yet
Development

No branches or pull requests

6 participants