question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow JSON-LD Scripts (error RZ9992: Script tags should not be placed inside components)

See original GitHub issue

Describe the bug

When I try to add JSON-LD to a Blazor Server application, I get the following error:

error RZ9992: Script tags should not be placed inside components because they cannot be updated dynamically. To fix this, move the script tag to the 'index.html' file or another static location. For more information see https://go.microsoft.com/fwlink/?linkid=872131

This makes 100% sense for script tags that contain JavaScript, but this should not be the case for JSON-LD. JSON-LD is just static JSON that provides structured data to search engines. There’s no danger in including JSON-LD scripts inside of Blazor Server, or any Blazor. (This wasn’t an error in Blazor WASM).

The workaround, for now, is to make it into one big string and cast it to MarkupString:

@((MarkupString)@"<script type=""application/ld+json"">
{
""@context"": ""https://schema.org/"",
""@type"": ""Recipe"",
""name"": ""Party Coffee Cake"",
""author"": {
    ""@type"": ""Person"",
    ""name"": ""Mary Stone""
},
""datePublished"": ""2018-03-10"",
""description"": ""This coffee cake is awesome and perfect for parties."",
""prepTime"": ""PT20M""
}
</script>"

I usually put JSON-LD inside of the head of the document, which I want to do using the new HeadContent component, but they could be placed anywhere inside of the body of the document too.

I think the error should become a warning, or be possible to disable, or not be raised when the type on the script tag is set to ‘application/ld+json’. I guess there may be other script types that could be legal, but I am not aware of others.

To Reproduce

  1. Create a new Blazor Server application using .NET 6 (I’m using RC1)
  2. Add the following snippet to Counter.razor:
<HeadContent>
    <script type="application/ld+json">
    {
    "@@context": "https://schema.org/",
    "@@type": "Recipe",
    "name": "Party Coffee Cake",
    "author": {
        "@@type": "Person",
        "name": "Mary Stone"
    },
    "datePublished": "2018-03-10",
    "description": "This coffee cake is awesome and perfect for parties.",
    "prepTime": "PT20M"
    }
    </script>
</HeadContent>

Exceptions (if any)

error RZ9992: Script tags should not be placed inside components because they cannot be updated dynamically. To fix this, move the script tag to the ‘index.html’ file or another static location. For more information see https://go.microsoft.com/fwlink/?linkid=872131

Further technical details

  • Include the output of dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100-rc.1.21463.6
 Commit:    e627d556a1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\

Host (useful for support):
  Version: 6.0.0-rc.1.21451.13
  Commit:  d7619cd4b1

.NET SDKs installed:
  3.1.413 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]
  5.0.104 [C:\Program Files\dotnet\sdk]
  5.0.207 [C:\Program Files\dotnet\sdk]
  5.0.303 [C:\Program Files\dotnet\sdk]
  5.0.400 [C:\Program Files\dotnet\sdk]
  5.0.401 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.1.21463.6 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.1.21451.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
doanhquang2005commented, Dec 7, 2021

I am a developer and SEOer, this is very important for SEO. I think need update in .net 6

2reactions
TanayParikhcommented, Oct 19, 2021

Maybe we can put application/ld+json under an allow list for <script> tags. Hesitant to put application/javascript under the block list, as that may inadvertently allow a lot more than we want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

.net - Blazor WASM Script tags should not be placed inside ...
Script tags should not be placed inside components because they cannot be updated dynamically. To fix this, move the script tag to the...
Read more >
Blazor Error: Script tags should not be placed inside ...
Script tags should not be placed inside components because they cannot be updated dynamically. To fix this, move the script tag to the...
Read more >
Blazor WASM Script tags should not be placed inside ...
Coding example for the question Blazor WASM Script tags should not be placed inside components because they cannot be updated dynamically.
Read more >
Update the HTML head from a Blazor component
Hi Emanuele, The metadata I need to place on head is not available until OnAfterRenderAsync event, but he headoutlet does not seem to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found