canjs / can-stache

Live binding handlebars templates
https://canjs.com/doc/can-stache.html
MIT License
10 stars 13 forks source link

Portal doesn't render magic tags inside <script> tag #728

Open cherifGsoul opened 4 years ago

cherifGsoul commented 4 years ago

This was submitted in done-autorender by @MarcGodard

Not sure if this is related to https://github.com/donejs/autorender/issues/160

I am also using the {{#portal (head)}}{{/portal}} in my head and the changes I am making are in the portal.

I am trying to add:

<script type="application/ld+json">{{seoSchema}}</script>

based on adding schema.org schema json to the head of my page. It is recommended to be in the head, but I also tried the body with the same results.

In SSR, when the variable includes the script tag, everything works, until SSR detaches (which the point of schema, this is fine as its only for SEO). If the script tag is in the stache file and the variable like the above, the variable doesn't get processed in either SSR or after it is detached. And actually completely disappears in the body.

Nothing changes in the head or the body when using data-keep from the first link in this issue other than it stays in the body.

I also tried without using portal, and same difference in the head tag.

The magic tags inside script tag are not rendered like is described.

cherifGsoul commented 4 years ago

Seems script tags are not processed in can-view-parser. https://github.com/canjs/can-view-parser/blob/e42c647f2f2a4304657e74efb70c424fb5616197/can-view-parser.js#L249

MarcGodard commented 4 years ago

@cherifGsoul Is it possible to add a type to it so it will process it?

cherifGsoul commented 4 years ago

@MarcGodard I don't think adding type will fix it, however after I discussed the issue with the team @bmomberger-bitovi pointed a good solution to make your use case working:

<script type="application/ld+json" innerHTML:from="seoSchema"></script>

This renders the property as expected and I checked it with portals in donejs example and it works fine, let us know if this works for you.

MarcGodard commented 4 years ago

@cherifGsoul Awesome, I will try that. Thanks @bmomberger-bitovi

cherifGsoul commented 4 years ago

@MarcGodard did the suggested solution work for you?

MarcGodard commented 4 years ago

@cherifGsoul Actually, it did not, because I am using a helper function.

<script type="application/ld+json" innerHTML:from="l10n ('pageNewsSchema')"></script>

The helper is like a look up, looks up the variable with locales and gives that language version of it.