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

Mention that App.razor always renders statically #31740

Closed
mrlife opened this issue Feb 8, 2024 · 7 comments · Fixed by #31867
Closed

Mention that App.razor always renders statically #31740

mrlife opened this issue Feb 8, 2024 · 7 comments · Fixed by #31867

Comments

@mrlife
Copy link
Contributor

mrlife commented Feb 8, 2024

Description

The App.razor component always renders statically. One implication is that any services included via @inject directives in _Imports.razor will be created more than once if App.razor's children contain a different render mode.

Everything I've seen about render modes up until now talked about how services would be created more than once if pre-rendering was enabled (once for pre-render and once for the regular render). So, the first paragraph above was unexpected.

ref: dotnet/aspnetcore#53804 (comment)

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/components/render-modes.md

Document ID

7c9948a3-9886-8097-6014-492a4c21ea4e

Article author

@guardrex

Copy link
Contributor

github-actions bot commented Feb 8, 2024

💘 Hello, February! Goodbye, New Year's resolutions! 😆

A green dinosaur 🦖 will be along shortly to assist. Stand-by ........

@guardrex
Copy link
Collaborator

guardrex commented Feb 8, 2024

Thanks @mrlife ... I'll get to this as soon as I can, but I'm buried in work at the moment. In the meantime, for ...

So, the first paragraph above was unexpected.

Can you clarify which paragraph?

@mrlife
Copy link
Contributor Author

mrlife commented Feb 8, 2024

Hi, @guardrex! Thank you, the paragraph referred to is:

The App.razor component always renders statically. One implication is that any services included via @Inject directives in _Imports.razor will be created more than once if App.razor's children contain a different render mode.

@guardrex
Copy link
Collaborator

guardrex commented Feb 8, 2024

Oh, I see 😄 ... that WAS the paragraph.

@guardrex
Copy link
Collaborator

@mrlife ... I'm looking at this now.

Is the only workaround to @Inject into each razor component instead of in _Imports.razor?

Did you try placing an _Imports.razor file with the service injection in the Pages folder and confirm that it won't apply to the App component from there?

@mrlife
Copy link
Contributor Author

mrlife commented Feb 20, 2024

@guardrex, that is an excellent point. Yes, that would be a better workaround than my initial thought of each component.

@guardrex
Copy link
Collaborator

Very well ... I'm working that idea into the PR that I'm working on. I'll ping you on the PR shortly and we can take a look at my ideas for addressing this situation.

@guardrex guardrex moved this from 8.0 to In progress in Blazor.Docs Feb 20, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in Blazor.Docs Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants