Skip to content

Razor Components - Parameters passed through RenderComponentAsync are lost after Prerendering #8596

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

Closed
plasticalligator opened this issue Mar 17, 2019 · 4 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components
Milestone

Comments

@plasticalligator
Copy link

plasticalligator commented Mar 17, 2019

Describe the bug

Parameters passed through RenderComponentAsync are lost immediately after prerendering.

To Reproduce

Steps to reproduce the behavior:
Razor Components Preview3 0.9
@(await Html.RenderComponentAsync<html>(new { Example = "something" }))

[Parameter] private string Example {get; set;} is null after prerendering is finished.

Expected behavior

For passed parameters to persist after prerendering is finished.

This is probably an actual issue (it could just be countless hours of sleep derivation at this point).

I figured out a workaround after posting this by creating a component and juggling the parameters; but the reality is the way I was trying to initially do this should have worked out of the box. Whenever I passed Example into the Cascade, it would always be null after Prerendering was finished.

To give you an idea of the weirdness I'm doing at 4:40 AM...
This works as expected, when inside of Body.razor you pass the reference forward as a CascadeValue so that the children Components can get access to the Metatags object.

So yeah, as of 5:40 AM I now have fully proper SEO.. without any weird hacking up Index.cshtml and using unclosed tags.

    public class html : ComponentBase
    {
        public static string HeadTXT = File.ReadAllText("head.htm");
        Metatags meta = new Metatags() { Title = "zzzzzzzz" };
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            builder.OpenElement(0, "head");
            builder.AddMarkupContent(1, HeadTXT);
            builder.OpenComponent<Head>(2);
            builder.AddAttribute(3, "MetaInfo", meta);
            builder.CloseComponent();
            builder.CloseElement();

            builder.OpenElement(4, "body");
            builder.OpenComponent<Body>(5);
            builder.AddAttribute(6, "MetaInfo", meta);
            builder.CloseComponent();
            builder.AddMarkupContent(7, "<script src=\"_framework/components.server.js\"></script>");
            builder.CloseElement();

        }
    }

)

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Mar 18, 2019
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Mar 18, 2019
@mkArtakMSFT
Copy link
Contributor

Thanks for contacting us, @Honkmother.
@javiercn can you please look into this? Thanks!

@javiercn
Copy link
Member

This is by design for now until we finish the "robust reconnect" feature.

@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Mar 19, 2019
@SteveSandersonMS
Copy link
Member

Closing as by design currently, though as @javiercn notes, we will later add a feature that changes this design.

@javiercn
Copy link
Member

Related issue: #8034

@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

5 participants