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

Issue: CSS files from ModuleInfo are results as script in the HTML file #3637

Closed
chrgei opened this issue Jan 11, 2024 · 2 comments
Closed

Comments

@chrgei
Copy link

chrgei commented Jan 11, 2024

I have the following Code in a Module:

 public ModuleDefinition ModuleDefinition => new ModuleDefinition
 {
     // ...
     Resources = new List<Resource>
     {
        new Resource
        {
            ResourceType = ResourceType.Stylesheet,
            Url = "_content/Havit.Blazor.Components.Web.Bootstrap/defaults.css",
            Level = ResourceLevel.Site
        }
     },
 };

This definition results in the HTML file as:

    <script src="/_content/Havit.Blazor.Components.Web.Bootstrap/defaults.css"></script>

I found the reason in the file Oqtane.Server\Pages_Host.cshtml.cs, Line 205:

    foreach (var script in scripts)
    {
        AddScript(script, alias);
    }

should be changed to

    foreach (var script in scripts.Where(x=> x.ResourceType == ResourceType.Script))
    {
        AddScript(script, alias);
    }

The handling of CSS files seems to be completely missing.

@sbwalker
Copy link
Member

sbwalker commented Jan 12, 2024

@chrgei thank you for reporting this issue. The ResourceLevel.Site property is only applicable to script resources (this is because script resources require special handling in Blazor). You should either not specify the Level or set it to ResourceLevel.Module for stylesheets. The fix you suggested would solve the issue - however it should actually be implemented at a lower framework level so that stylesheet items are never added to the collection.

sbwalker added a commit that referenced this issue Jan 12, 2024
fix #3637 - ensure ServerState Scripts only contains site level script resources
@chrgei
Copy link
Author

chrgei commented Jan 12, 2024

@sbwalker thank for the fast answer. I think it's better to solve this with a special theme.

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

No branches or pull requests

2 participants