Skip to content

Commit b251d95

Browse files
Give error if the root component is interactive. Fixes #48847 (#48945)
1 parent 117dda3 commit b251d95

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

src/Components/Endpoints/src/RazorComponentEndpointHost.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ internal class RazorComponentEndpointHost : IComponent
1919
{
2020
private RenderHandle _renderHandle;
2121

22-
[Parameter] public IComponentRenderMode? RenderMode { get; set; }
2322
[Parameter] public Type ComponentType { get; set; } = default!;
2423
[Parameter] public IReadOnlyDictionary<string, object?>? ComponentParameters { get; set; }
2524

@@ -45,16 +44,6 @@ private void BuildRenderTree(RenderTreeBuilder builder)
4544

4645
private void RenderPageWithParameters(RenderTreeBuilder builder)
4746
{
48-
// TODO: Once we support rendering Server/WebAssembly components into the page, implementation will
49-
// go here. We need to switch into the rendermode given by RazorComponentResult.RenderMode for this
50-
// child component. That will cause the developer-supplied parameters to be serialized into a marker
51-
// but not attempt to serialize the RenderFragment that causes this to be hosted in its layout.
52-
if (RenderMode is not null)
53-
{
54-
// Tracked by #46353 and #46354
55-
throw new NotSupportedException($"Currently, Razor Component endpoints don't support setting a render mode.");
56-
}
57-
5847
builder.OpenComponent(0, ComponentType);
5948

6049
if (ComponentParameters is not null)

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Services/ComponentDescriptorDiscovery.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function getComponentComment(commentNodeIterator: ComponentCommentIterator, type
140140
const json = definition && definition.groups && definition.groups['descriptor'];
141141

142142
if (json) {
143+
assertNotDirectlyOnDocument(candidateStart);
143144
try {
144145
const componentComment = parseCommentPayload(json);
145146
switch (type) {
@@ -167,6 +168,12 @@ function parseCommentPayload(json: string): ComponentComment {
167168
return payload;
168169
}
169170

171+
function assertNotDirectlyOnDocument(marker: Node) {
172+
if (marker.parentNode instanceof Document) {
173+
throw new Error('Root components cannot be marked as interactive. The <html> element must be rendered statically so that scripts are not evaluated multiple times.');
174+
}
175+
}
176+
170177
function createServerComponentComment(payload: ServerComponentComment, start: Node, iterator: ComponentCommentIterator): ServerComponentComment | undefined {
171178
const { type, descriptor, sequence, prerenderId } = payload;
172179

0 commit comments

Comments
 (0)