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

make ISpaPrerenderer.RenderToString and aspnet-prerendering createServerRenderer to generic #12253

Closed
petvas opened this issue Jul 16, 2019 · 1 comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-spa

Comments

@petvas
Copy link

petvas commented Jul 16, 2019

Is your feature request related to a problem? Please describe.

Microsoft.AspNetCore.SpaServices.Prerendering.RenderToStringResult has one Globals in it, it works ok with an example application but in real life I ended up overloading it.
Example:
Basic react app with ssr:

server side entry point looks like this:

const helmetData = Helmet.renderStatic();
        const helmet = {
            baseString: helmetData.base.toString(),
            bodyAttributes: helmetData.bodyAttributes.toString(),
            htmlAttributes: helmetData.htmlAttributes.toString(),
            link: helmetData.link.toString(),
            meta: helmetData.meta.toString(),
            noscript: helmetData.noscript.toString(), // :D
            script: helmetData.script.toString(),
            style: helmetData.style.toString(),
            title: helmetData.title.toString(),
        };


resolve({
            html: result,
            globals: {
                scriptTags,
                linkTags,
                styleTags,
                helmet,
                PreloadedState,
            }
        });

AspNetCore looks like this:

 public class HelmetData {
        public string baseString;
        public string bodyAttributes;
        public string htmlAttributes;
        public string link;
        public string meta;
        public string noscript;
        public string script;
        public string style;
        public string title;
    }
    public class SSRExtraParams
    {
        public string scriptTags;
        public string linkTags;
        public string styleTags;
        public HelmetData helmet;
        public JObject PreloadedState;
    }

           var result = await prerenderer.RenderToString("ssrroot/dist/ssr", null, new { test = "test"  });
            
            ViewData["PrerenderedHtml"] = result.Html;

            var extraParams = result.Globals.ToObject<SSRExtraParams>();

            ViewData["scriptTags"] = extraParams.scriptTags;
            ViewData["linkTags"] = extraParams.linkTags;
            ViewData["styleTags"] = extraParams.styleTags;
            ViewData["helmet"] = extraParams.helmet;
            ViewData["PreloadedState"] = extraParams.PreloadedState;

Describe the solution you'd like

I would like to make RenderToString generic on server side:

var result = await prerenderer.RenderToString<MyCustomRenderToStringResult>(/*...*/);

and aspnet-prerendering createServerRenderer generic on client side:

createServerRenderer<MyCustomRenderResult>((params) => {/*...*/})

Additional context

It just feels using global like this is not right, it would be more elegant end flexible if we can set the return type so its suits better with everyone needs.

@mkArtakMSFT mkArtakMSFT added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-spa spa-announcement and removed spa-announcement labels Jul 16, 2019
@mkArtakMSFT mkArtakMSFT added this to the spa-announcement milestone Jul 29, 2019
@mkArtakMSFT
Copy link
Member

We're closing this issue as this doesn't align with our long-term plans in this area. You can read more details about our vision for this area at #12890.

@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-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-spa
Projects
None yet
Development

No branches or pull requests

2 participants