-
Notifications
You must be signed in to change notification settings - Fork 58
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
JavaScript Collocation TagHelper #42
Comments
@khalidabuhakmeh Hmm, we're trying to use this ourselves but in production, it doesn't seem to work. The files are correctly under wwwroot, but the script tag isn't being rendered. |
Be sure you're importing the correct namespace with @addTagHelepers call in your ViewImports file. |
Just noticed this! This would be great to add. If you're still up for it, you can add |
Hmm, AFAIK it was correct. Still doesn't work in actual production here .. hmm. |
Honestly, I forget why I wrote this in the first place. 😅 I'll have to try it again or find the sample somewhere. Please hold as I try this in the next couple of days. |
OK, I remember now. I created a sample that shows it working. It's actually a good idea! (I have a couple of those a year). I hope this helps @kfrancis. https://github.com/khalidabuhakmeh/ColocationTagHelperSample |
@khalidabuhakmeh So, still can't get it to work. We have a ton of razor pages, so perhaps it cares about the namespace really particularly? In your sample, the namespace is just basically |
Are you attempting colocation at a top level Razor element (View, Razor Page Razor component)? This will not work with partials. |
Only top-level razor pages. |
I'm not sure what to tell you at this point, without seeing your solution :( |
I'm facing the same issue like @kfrancis. Tag works in dev but no script tag rendered in prod. |
The problem is caused by this line: var fileInfo = environment.ContentRootFileProvider.GetFileInfo(src) ??
environment.WebRootFileProvider.GetFileInfo(src);
This works both in dev and prod: var exists = environment.ContentRootFileProvider.GetFileInfo(src).Exists ||
environment.WebRootFileProvider.GetFileInfo(src).Exists;
if (exists) |
Well... damn. Sorry folks. Thanks, @AlexZeitler, for catching that. |
I've updated the code above for brave souls who don't read below the big fancy code blocks. |
Thank you @AlexZeitler for finding that! |
This is in reference to a .NET 6 feature known as JavaScript collocation. https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-6.0#load-a-script-from-an-external-javascript-file-js-collocated-with-a-component
I wanted to submit a PR but noticed you are multi-targeting .NET 3.1 and .NET 4.7.1 with this package. Seeing that JavaScript collocation is part of .NET 6 I'm not sure what to do. In any case, I've included the code below in the chance you'd like to add it to your library.
Usage
Add the following to the end of your
_Layout.cshtml
file.The text was updated successfully, but these errors were encountered: