Skip to content

Commit 538eafc

Browse files
authored
Update master with release/3.0-preview9 (#14147)
Update master with release/3.0-preview9
2 parents 4bd7dc6 + 3752039 commit 538eafc

35 files changed

+942
-256
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<Router AppAssembly="typeof(Program).Assembly">
2-
<NotFoundContent>
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
36
<p>Sorry, there's nothing at this address.</p>
4-
</NotFoundContent>
7+
</NotFound>
58
</Router>

aspnetcore/blazor/common/samples/3.x/BlazorSample/BlazorSample.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview8.19405.7" />
12-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
13-
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview8.19405.7" />
14-
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19424.4" />
12+
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
13+
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19424.4" />
14+
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
1515
</ItemGroup>
1616

1717
</Project>

aspnetcore/blazor/common/samples/3.x/BlazorSample/Components/ChildComponent.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
public RenderFragment ChildContent { get; set; }
1616

1717
[Parameter]
18-
public EventCallback<UIMouseEventArgs> OnClick { get; set; }
18+
public EventCallback<MouseEventArgs> OnClick { get; set; }
1919
}
2020

aspnetcore/blazor/common/samples/3.x/BlazorSample/Components/HTTPRequestTester.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@using Microsoft.AspNetCore.Blazor.Http
22
@inject HttpClient Http
3-
@inject IUriHelper UriHelper
3+
@inject NavigationManager NavigationManager
44

55
<h2>HTTP Request Tester</h2>
66

@@ -98,7 +98,7 @@
9898

9999
protected override void OnInitialized()
100100
{
101-
_requestReferrer = UriHelper.GetAbsoluteUri();
101+
_requestReferrer = NavigationManager.Uri;
102102
}
103103

104104
private async void DoRequest()

aspnetcore/blazor/common/samples/3.x/BlazorSample/JsInteropClasses/ExampleJsInterop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public ExampleJsInterop(IJSRuntime jsRuntime)
1717
_jsRuntime = jsRuntime;
1818
}
1919

20-
public Task CallHelloHelperSayHello(string name)
20+
public ValueTask<object> CallHelloHelperSayHello(string name)
2121
{
2222
// sayHello is implemented in wwwroot/exampleJsInterop.js
2323
return _jsRuntime.InvokeAsync<object>(
2424
"exampleJsFunctions.sayHello",
25-
DotNetObjectRef.Create(new HelloHelper(name)));
25+
DotNetObjectReference.Create(new HelloHelper(name)));
2626
}
2727
}
2828
#endregion

aspnetcore/blazor/common/samples/3.x/BlazorSample/Pages/ParentComponent.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@code {
1515
private string messageText;
1616

17-
private void ShowMessage(UIMouseEventArgs e)
17+
private void ShowMessage(MouseEventArgs e)
1818
{
1919
messageText = "Blaze a new trail with Blazor!";
2020
}
@@ -44,7 +44,7 @@
4444
@@code {
4545
private string messageText;
4646

47-
private void ShowMessage(UIMouseEventArgs e)
47+
private void ShowMessage(MouseEventArgs e)
4848
{
4949
messageText = "Blaze a new trail with Blazor!";
5050
}
@@ -67,5 +67,5 @@
6767
public RenderFragment ChildContent { get; set; }
6868

6969
[Parameter]
70-
public EventCallback&lt;UIMouseEventArgs&gt; OnClick { get; set; }
70+
public EventCallback&lt;MouseEventArgs&gt; OnClick { get; set; }
7171
}</code></pre>

aspnetcore/blazor/common/samples/3.x/BlazorSample/Pages/_Imports.razor

Lines changed: 0 additions & 1 deletion
This file was deleted.

aspnetcore/blazor/common/samples/3.x/BlazorSample/_Imports.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@using System.Net.Http
22
@using Microsoft.AspNetCore.Components.Forms
33
@using Microsoft.AspNetCore.Components.Routing
4+
@using Microsoft.AspNetCore.Components.Web
45
@using Microsoft.JSInterop
56
@using BlazorSample
67
@using BlazorSample.Shared

aspnetcore/blazor/components.md

Lines changed: 88 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to create and use Razor components, including how to bind
55
monikerRange: '>= aspnetcore-3.0'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 09/02/2019
8+
ms.date: 09/04/2019
99
uid: blazor/components
1010
---
1111
# Create and use ASP.NET Core Razor components
@@ -66,8 +66,8 @@ Use components with existing Razor Pages and MVC apps. There's no need to rewrit
6666
To render a component from a page or view, use the `RenderComponentAsync<TComponent>` HTML helper method:
6767

6868
```cshtml
69-
<div id="Counter">
70-
@(await Html.RenderComponentAsync<Counter>(new { IncrementAmount = 10 }))
69+
<div id="MyComponent">
70+
@(await Html.RenderComponentAsync<MyComponent>(RenderMode.ServerPrerendered))
7171
</div>
7272
```
7373

@@ -414,23 +414,23 @@ In the following example, `UpdateHeading` is called asynchronously when the butt
414414

415415
For some events, event argument types are permitted. If access to one of these event types isn't necessary, it isn't required in the method call.
416416

417-
Supported [UIEventArgs](https://github.com/aspnet/AspNetCore/blob/release/3.0-preview8/src/Components/Components/src/UIEventArgs.cs) are shown in the following table.
417+
Supported [EventArgs](https://github.com/aspnet/AspNetCore/tree/release/3.0-preview9/src/Components/Web/src/Web) are shown in the following table.
418418

419419
| Event | Class |
420420
| ----- | ----- |
421-
| Clipboard | `UIClipboardEventArgs` |
422-
| Drag | `UIDragEventArgs` &ndash; `DataTransfer` is used to hold the dragged data during a drag and drop operation and may hold one or more `UIDataTransferItem`. `UIDataTransferItem` represents one drag data item. |
423-
| Error | `UIErrorEventArgs` |
424-
| Focus | `UIFocusEventArgs` &ndash; Doesn't include support for `relatedTarget`. |
425-
| `<input>` change | `UIChangeEventArgs` |
426-
| Keyboard | `UIKeyboardEventArgs` |
427-
| Mouse | `UIMouseEventArgs` |
428-
| Mouse pointer | `UIPointerEventArgs` |
429-
| Mouse wheel | `UIWheelEventArgs` |
430-
| Progress | `UIProgressEventArgs` |
431-
| Touch | `UITouchEventArgs` &ndash; `UITouchPoint` represents a single contact point on a touch-sensitive device. |
432-
433-
For information on the properties and event handling behavior of the events in the preceding table, see [EventArgs classes in the reference source (aspnet/AspNetCore release/3.0-preview9 branch)](https://github.com/aspnet/AspNetCore/tree/release/3.0-preview9/src/Components/Web/src).
421+
| Clipboard | `ClipboardEventArgs` |
422+
| Drag | `DragEventArgs` &ndash; `DataTransfer` and `DataTransferItem` hold dragged item data. |
423+
| Error | `ErrorEventArgs` |
424+
| Focus | `FocusEventArgs` &ndash; Doesn't include support for `relatedTarget`. |
425+
| `<input>` change | `ChangeEventArgs` |
426+
| Keyboard | `KeyboardEventArgs` |
427+
| Mouse | `MouseEventArgs` |
428+
| Mouse pointer | `PointerEventArgs` |
429+
| Mouse wheel | `WheelEventArgs` |
430+
| Progress | `ProgressEventArgs` |
431+
| Touch | `TouchEventArgs` &ndash; `TouchPoint` represents a single contact point on a touch-sensitive device. |
432+
433+
For information on the properties and event handling behavior of the events in the preceding table, see [EventArgs classes in the reference source (aspnet/AspNetCore release/3.0-preview9 branch)](https://github.com/aspnet/AspNetCore/tree/release/3.0-preview9/src/Components/Web/src/Web).
434434

435435
### Lambda expressions
436436

@@ -517,10 +517,9 @@ Component references provide a way to reference a component instance so that you
517517

518518
* Add an [@ref](xref:mvc/views/razor#ref) attribute to the child component.
519519
* Define a field with the same type as the child component.
520-
* Provide the `@ref:suppressField` parameter, which suppresses backing field generation. For more information, see [Removing automatic backing field support for @ref in 3.0.0-preview9](https://github.com/aspnet/Announcements/issues/381).
521520

522521
```cshtml
523-
<MyLoginDialog @ref="loginDialog" @ref:suppressField ... />
522+
<MyLoginDialog @ref="loginDialog" ... />
524523
525524
@code {
526525
private MyLoginDialog loginDialog;
@@ -537,34 +536,67 @@ When the component is rendered, the `loginDialog` field is populated with the `M
537536
> [!IMPORTANT]
538537
> The `loginDialog` variable is only populated after the component is rendered and its output includes the `MyLoginDialog` element. Until that point, there's nothing to reference. To manipulate components references after the component has finished rendering, use the `OnAfterRenderAsync` or `OnAfterRender` methods.
539538
540-
<!-- HOLD https://github.com/aspnet/AspNetCore.Docs/pull/13818
541-
Component references provide a way to reference a component instance so that you can issue commands to that instance, such as `Show` or `Reset`.
539+
While capturing component references use a similar syntax to [capturing element references](xref:blazor/javascript-interop#capture-references-to-elements), it isn't a [JavaScript interop](xref:blazor/javascript-interop) feature. Component references aren't passed to JavaScript code&mdash;they're only used in .NET code.
542540

543-
The Razor compiler automatically generates a backing field for element and component references when using [@ref](xref:mvc/views/razor#ref). In the following example, there's no need to create a `myLoginDialog` field for the `LoginDialog` component:
541+
> [!NOTE]
542+
> Do **not** use component references to mutate the state of child components. Instead, use normal declarative parameters to pass data to child components. Use of normal declarative parameters result in child components that rerender at the correct times automatically.
544543
545-
```cshtml
546-
<LoginDialog @ref="myLoginDialog" ... />
544+
## Invoke component methods externally to update state
547545

548-
@code {
549-
private void OnSomething()
546+
Blazor uses a `SynchronizationContext` to enforce a single logical thread of execution. A component's lifecycle methods and any event callbacks that are raised by Blazor are executed on this `SynchronizationContext`. In the event a component must be updated based on an external event, such as a timer or other notifications, use the `InvokeAsync` method, which will dispatch to Blazor's `SynchronizationContext`.
547+
548+
For example, consider a *notifier service* that can notify any listening component of the updated state:
549+
550+
```csharp
551+
public class NotifierService
552+
{
553+
// Can be called from anywhere
554+
public async Task Update(string key, int value)
550555
{
551-
myLoginDialog.Show();
556+
if (Notify != null)
557+
{
558+
await Notify.Invoke(key, value);
559+
}
552560
}
561+
562+
public event Action<string, int, Task> Notify;
553563
}
554564
```
555565

556-
When the component is rendered, the generated `myLoginDialog` field is populated with the `LoginDialog` component instance. You can then invoke .NET methods on the component instance.
566+
Usage of the `NotifierService` to update a component:
557567

558-
In some cases, a backing field is required. For example, declare a backing field when referencing generic components. To suppress backing field generation, specify the `@ref:suppressField` parameter.
568+
```cshtml
569+
@page "/"
570+
@inject NotifierService Notifier
571+
@implements IDisposable
559572
560-
> [!IMPORTANT]
561-
> The generated `myLoginDialog` variable is only populated after the component is rendered and its output includes the `LoginDialog` element. Until that point, there's nothing to reference. To manipulate components references after the component has finished rendering, use the `OnAfterRenderAsync` or `OnAfterRender` methods.
562-
-->
573+
<p>Last update: @lastNotification.key = @lastNotification.value</p>
563574
564-
While capturing component references use a similar syntax to [capturing element references](xref:blazor/javascript-interop#capture-references-to-elements), it isn't a [JavaScript interop](xref:blazor/javascript-interop) feature. Component references aren't passed to JavaScript code&mdash;they're only used in .NET code.
575+
@code {
576+
private (string key, int value) lastNotification;
565577
566-
> [!NOTE]
567-
> Do **not** use component references to mutate the state of child components. Instead, use normal declarative parameters to pass data to child components. Use of normal declarative parameters result in child components that rerender at the correct times automatically.
578+
protected override void OnInitialized()
579+
{
580+
Notifier.Notify += OnNotify;
581+
}
582+
583+
public async Task OnNotify(string key, int value)
584+
{
585+
await InvokeAsync(() =>
586+
{
587+
lastNotification = (key, value);
588+
StateHasChanged();
589+
});
590+
}
591+
592+
public void Dispose()
593+
{
594+
Notifier.Notify -= OnNotify;
595+
}
596+
}
597+
```
598+
599+
In the preceding example, `NotifierService` invokes the component's `OnNotify` method outside of Blazor's `SynchronizationContext`. `InvokeAsync` is used to switch to the correct context and queue a render.
568600

569601
## Use \@key to control the preservation of elements and components
570602

@@ -1356,7 +1388,7 @@ public class CultureController : Controller
13561388
The following component shows an example of how to perform the initial redirection when the user selects a culture:
13571389

13581390
```cshtml
1359-
@inject IUriHelper UriHelper
1391+
@inject NavigationManager NavigationManager
13601392
13611393
<h3>Select your language</h3>
13621394
@@ -1372,12 +1404,12 @@ The following component shows an example of how to perform the initial redirecti
13721404
private void OnSelected(UIChangeEventArgs e)
13731405
{
13741406
var culture = (string)e.Value;
1375-
var uri = new Uri(UriHelper.GetAbsoluteUri())
1407+
var uri = new Uri(NavigationManager.Uri())
13761408
.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
13771409
var query = $"?culture={Uri.EscapeDataString(culture)}&" +
13781410
$"redirectUri={Uri.EscapeDataString(uri)}";
13791411
1380-
UriHelper.NavigateTo("/Culture/SetCulture" + query, forceLoad: true);
1412+
NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true);
13811413
}
13821414
}
13831415
```
@@ -1397,3 +1429,21 @@ A limited set of ASP.NET Core's localization scenarios are currently supported:
13971429
* `IHtmlLocalizer<>`, `IViewLocalizer<>`, and Data Annotations localization are ASP.NET Core MVC scenarios and **not supported** in Blazor apps.
13981430

13991431
For more information, see <xref:fundamentals/localization>.
1432+
1433+
## Scalable Vector Graphics (SVG) images
1434+
1435+
Since Blazor renders HTML, browser-supported images, including Scalable Vector Graphics (SVG) images (*.svg*), are supported via the `<img>` tag:
1436+
1437+
```html
1438+
<img alt="Example image" src="some-image.svg" />
1439+
```
1440+
1441+
Similarly, SVG images are supported in the CSS rules of a stylesheet file (*.css*):
1442+
1443+
```css
1444+
.my-element {
1445+
background-image: url("some-image.svg");
1446+
}
1447+
```
1448+
1449+
However, inline SVG markup isn't supported in all scenarios. If you place an `<svg>` tag directly into a component file (*.razor*), basic image rendering is supported but many advanced scenarios aren't yet supported. For example, `<use>` tags aren't currently respected, and `@bind` can't be used with some SVG tags. We expect to address these limitations in a future release.

aspnetcore/blazor/dependency-injection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Default services are automatically added to the app's service collection.
2727
| ------- | -------- | ----------- |
2828
| <xref:System.Net.Http.HttpClient> | Singleton | Provides methods for sending HTTP requests and receiving HTTP responses from a resource identified by a URI. Note that this instance of `HttpClient` uses the browser for handling the HTTP traffic in the background. [HttpClient.BaseAddress](xref:System.Net.Http.HttpClient.BaseAddress) is automatically set to the base URI prefix of the app. For more information, see <xref:blazor/call-web-api>. |
2929
| `IJSRuntime` | Singleton | Represents an instance of a JavaScript runtime where JavaScript calls are dispatched. For more information, see <xref:blazor/javascript-interop>. |
30-
| `IUriHelper` | Singleton | Contains helpers for working with URIs and navigation state. For more information, see [URI and navigation state helpers](xref:blazor/routing#uri-and-navigation-state-helpers). |
30+
| `NavigationManager` | Singleton | Contains helpers for working with URIs and navigation state. For more information, see [URI and navigation state helpers](xref:blazor/routing#uri-and-navigation-state-helpers). |
3131

3232
A custom service provider doesn't automatically provide the default services listed in the table. If you use a custom service provider and require any of the services shown in the table, add the required services to the new service provider.
3333

0 commit comments

Comments
 (0)