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

Hydrate App: Can't pass JSON to component in renderToString method (SSR) #2551

Closed
guidoknoll opened this issue Jul 5, 2020 · 4 comments
Closed
Labels

Comments

@guidoknoll
Copy link

guidoknoll commented Jul 5, 2020

Stencil version:

I'm submitting a:

[ ] bug report
[x] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

When using the renderToString method of the hydrate app it's not possible to pass json to a component for initialization.

Expected behavior:

It should be possible to pass objects/json to a component during server side rendering.

Steps to reproduce:

Related code:

As shown below i would pass a config object to my widget component but this does not work with the tsx syntax in the node environment. Alternatively it should be possible to include complex attributes to the renderToString function.

   const renderedHtml = await stencil.renderToString(
        `<widget config='{}'></widget>`
        , {
            removeBooleanAttributeQuotes: true,
            prettyHtml: true,
            constrainTimeouts: false,
            runtimeLogging: true,
            timeout: 3000,
            maxHydrateCount: 700
        }
    );
    res.send(renderedHtml.html);

Other information:

@ionitron-bot ionitron-bot bot added the triage label Jul 5, 2020
@sajTempler
Copy link

It would be great to have it implemented, for now passing stringified object to the component looks awkward in output html (especially when the config object in above example is somehow complex)

@sajTempler
Copy link

similar to #1691

@sajTempler
Copy link

sajTempler commented Jan 25, 2021

@guidoknoll You can take a look at my simple example on how to get this working without passing the string as prop:

https://github.com/sajTempler/stencil-ssr

@christian-bromann
Copy link
Member

This will be possible with #5792 where you can do this:

    const { html } = await renderToString(`<another-car-detail car=${JSON.stringify(vento)}></another-car-detail>`, {
      serializeShadowRoot: true,
      fullDocument: false,
    });

I will go ahead and close the issue. Please comment on the PR for any feedback. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants