-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Allow declaring render modes, and emit the corresponding markers into HTML #48190
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Represents a render mode for a component. | ||
/// </summary> | ||
public interface IComponentRenderMode | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,9 +103,9 @@ public TValue GetValueOrDefault<TValue>(string parameterName, TValue defaultValu | |
/// Returns a dictionary populated with the contents of the <see cref="ParameterView"/>. | ||
/// </summary> | ||
/// <returns>A dictionary populated with the contents of the <see cref="ParameterView"/>.</returns> | ||
public IReadOnlyDictionary<string, object> ToDictionary() | ||
public IReadOnlyDictionary<string, object?> ToDictionary() | ||
{ | ||
var result = new Dictionary<string, object>(); | ||
var result = new Dictionary<string, object?>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The nullability annotation was wrong before. |
||
foreach (var entry in this) | ||
{ | ||
result[entry.Name] = entry.Value; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Specifies a fixed rendering mode for a component type. | ||
/// | ||
/// Where possible, components should not specify any render mode this way, and should | ||
/// be implemented to work across all render modes. Component authors should only specify | ||
/// a fixed rendering mode when the component is incapable of running in other modes. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public abstract class RenderModeAttribute : Attribute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to allow multiple for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. What would we do if there were multiple? This is about specifying a required rendermode, not a set of allowed rendermodes (which, if implemented in the future, would be a separate API). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean AllowMultiple = false There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the default. If I'm missing something and it has to be specified explicitly in this case, please let me know! |
||
{ | ||
/// <summary> | ||
/// Gets the fixed rendering mode for a component type. | ||
/// </summary> | ||
public abstract IComponentRenderMode Mode { get; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -952,15 +952,8 @@ private static void InitializeNewComponentFrame(ref DiffContext diffContext, int | |
{ | ||
var frames = diffContext.NewTree; | ||
ref var frame = ref frames[frameIndex]; | ||
|
||
if (frame.ComponentStateField != null) | ||
{ | ||
throw new InvalidOperationException($"Child component already exists during {nameof(InitializeNewComponentFrame)}"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check was redundant since |
||
|
||
var parentComponentId = diffContext.ComponentId; | ||
diffContext.Renderer.InstantiateChildComponentOnFrame(ref frame, parentComponentId); | ||
var childComponentState = frame.ComponentStateField; | ||
var childComponentState = diffContext.Renderer.InstantiateChildComponentOnFrame(ref frame, parentComponentId); | ||
|
||
// Set initial parameters | ||
var initialParametersLifetime = new ParameterViewLifetime(diffContext.BatchBuilder); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,4 +59,3 @@ public enum RenderTreeFrameType : short | |
/// </summary> | ||
Markup = 8, | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually, the changes in this file are:
ResolveComponentForRenderMode
to do the component instantiation. This is how a rendermode gets translated into concrete, platform-specific behavior.