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

Tag helpers don't work #8

Closed
carlreinke opened this issue Mar 20, 2023 · 5 comments
Closed

Tag helpers don't work #8

carlreinke opened this issue Mar 20, 2023 · 5 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@carlreinke
Copy link

Tag helpers appear to not work despite using @addTagHelper.

There's a lot of tag helper discovery code in the Razor SDK source generator that doesn't seem to have an equivalent in RazorBlade's source generator.

@ltrzesniewski
Copy link
Owner

Tag helpers are currently not implemented in RazorBlade.

To be honest I'm not sure I want to add them, as this library is meant to be lightweight. It's supposed to generate simple HTML output, not fully-fledged pages which communicate with a server. I don't really want to reimplement ASP.NET. 🙂

Also, I expect the IDE support for them to be poor (it wouldn't recognize the special tags, it would just treat them as regular markup).

In some cases, you can get a similar result by composing your templates: @(new SomeOtherTemplate(AndItsArgument)) or by using any other object which implements IEncodedContent instead.

If this is insufficient, could you tell me what you're trying to do, so I can see how tag helpers would help?

@ltrzesniewski ltrzesniewski added the enhancement New feature or request label Mar 20, 2023
@carlreinke
Copy link
Author

carlreinke commented Mar 21, 2023

I'm trying to generate URLs from routes (either using the built-in anchor tag helper or using a custom tag helper). Right now I have href="@(SomeUrlHelper.GetWhateverUrl(_context, someId))", but I think I'd rather have asp-route="whatever" asp-route-id="@someId" and not have to write URL a generator method for every route.

So I can certainly live without tag helpers, it just seemed like it might be convenient.

If tag helpers aren't going to be supported, it would be nice to produce an error from the generator if the template contains an @addTagHelper directive. The Razor compiler is pretty modular, but it looks like the @addTagHelper is built-in and can't be disabled. Maybe there's a way to examine the Razor syntax tree and produce a diagnostic on the directive syntax node or replace the IRazorTagHelperBinderPhase with one that produces a diagnostic?

@ltrzesniewski
Copy link
Owner

Ok, I see. I think I'll play with them in the future to see how it goes.

I didn't notice that @addTagHelper was currently accepted by the parser. Thanks for the info, I'll definitely add an error if I end up not adding tag helper support.

@ltrzesniewski
Copy link
Owner

I ended up adding an error when trying to use tag helpers.

I tried to add support for them in the tag-helpers branch, but realized it would go off the rails.

I wanted to integrate the Microsoft.AspNetCore.Razor.Runtime package (which implements tag helpers without depending on a lot of ASP.NET stuff) with RazorBlade: the idea was that you'd get tag helper support if you reference that package. Unfortunately, Microsoft deprecated it after I started implementing the feature. 🙄

So that's a dead end - it seems the tag helpers implementation will be shipped in the SDK, and not available as a nicely self-contained external NuGet package that I could use.

Also, integrating the Razor runtime package wouldn't be seamless, since it would import stuff that RazorBlade implements on its own, and you wouldn't necessarily know which feature should be used in a given context.

Maybe someday I could revisit this, but it's best to keep things simple for now I guess.

@ltrzesniewski ltrzesniewski closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2023
@ltrzesniewski ltrzesniewski added the wontfix This will not be worked on label Sep 17, 2023
@carlreinke
Copy link
Author

Thanks for trying to make it work anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants