Skip to content

Give error if the root component is interactive. Fixes #48847 #48945

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

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/Components/Endpoints/src/RazorComponentEndpointHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ internal class RazorComponentEndpointHost : IComponent
{
private RenderHandle _renderHandle;

[Parameter] public IComponentRenderMode? RenderMode { get; set; }
Copy link
Member Author

@SteveSandersonMS SteveSandersonMS Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaning up unused code. It's an internal component and we never supplied a value for this parameter, nor would it ever make sense for us to do so.

[Parameter] public Type ComponentType { get; set; } = default!;
[Parameter] public IReadOnlyDictionary<string, object?>? ComponentParameters { get; set; }

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

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

builder.OpenComponent(0, ComponentType);

if (ComponentParameters is not null)
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.web.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function getComponentComment(commentNodeIterator: ComponentCommentIterator, type
const json = definition && definition.groups && definition.groups['descriptor'];

if (json) {
assertNotDirectlyOnDocument(candidateStart);
try {
const componentComment = parseCommentPayload(json);
switch (type) {
Expand Down Expand Up @@ -167,6 +168,12 @@ function parseCommentPayload(json: string): ComponentComment {
return payload;
}

function assertNotDirectlyOnDocument(marker: Node) {
if (marker.parentNode instanceof Document) {
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.');
}
}

function createServerComponentComment(payload: ServerComponentComment, start: Node, iterator: ComponentCommentIterator): ServerComponentComment | undefined {
const { type, descriptor, sequence, prerenderId } = payload;

Expand Down