Using AddCssFileParts within a ViewComponent

1 anno tempo fa
Hi all!

I've been searching the forum for a solution but cannot find one, perhaps you guys can point me in the right direction.

I'm creating a plugin that overwrites Shared\Components\OrderSummary\Default.
Within this component I want to make some CSS changes (in this case to allign the order attributes to the left).

At the top of my Default.cshtml I place

But when I run the plugin, my custom css is not loaded.

Turns out it is a ViewComponent called with Component.InvokeAsync. The component calls the AddCssFileParts  AFTER the GenerateCssFiles in PageHeadBuilder.cs is called, so the added filepart is never generated and never ends up in the bundle.

I've now resolved this by also overwriting the page calling the invoke and adding the filepart there, but it feels like I'm missing the right solution.

Any advice?
8 mesi tempo fa
Just faced the same issue. I was trying to drop some css files via NopHtmlHelper.AddCssFileParts into "head_html_tag" widget zone and those css files did not appear on the page.
It happens because Razor renders page from the inside to the outside. Body of the page is rendered before the layout. But the .cshtml file is being processed line by line. So the @NopHtml.GenerateCssFiles() is executed before @await Component.InvokeAsync("Widget", new { widgetZone = PublicWidgetZones.HeadHtmlTag }) in _Root.Head.cshtml. That is why css files that are added in "head_html_tag" via NopHtmlHelper.AddCssFileParts or NopHtmlHelper.AppendCssFileParts or <link/> tag do not appear on the page.
<link> tag is very confusing because nop overrides default html <link/> tag and NopHtmlHelper.AddCssFileParts is used under the hood. Standard html <link/> tag can be used as <!link/> but there will be no bundling.