Skip to content

Commit f5e471f

Browse files
authored
Reconnection UI guidance updates (#34104)
1 parent 5f24330 commit f5e471f

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

aspnetcore/blazor/fundamentals/signalr.md

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -491,43 +491,71 @@ In the `Program` file, call <xref:Microsoft.AspNetCore.Builder.ComponentEndpoint
491491

492492
## Reflect the server-side connection state in the UI
493493

494-
When the client detects that the connection has been lost, a default UI is displayed to the user while the client attempts to reconnect. If reconnection fails, the user is provided the option to retry.
494+
If the client detects a lost connection to the server, a default UI is displayed to the user while the client attempts to reconnect:
495+
496+
:::moniker range=">= aspnetcore-9.0"
497+
498+
![The default reconnection UI.](signalr/_static/reconnection-ui-90-or-later.png)
499+
500+
:::moniker-end
501+
502+
:::moniker range="< aspnetcore-9.0"
503+
504+
![The default reconnection UI.](signalr/_static/reconnection-ui-80-or-earlier.png)
505+
506+
:::moniker-end
507+
508+
If reconnection fails, the user is instructed to retry or reload the page:
509+
510+
:::moniker range=">= aspnetcore-9.0"
511+
512+
![The default retry UI.](signalr/_static/retry-ui-90-or-later.png)
513+
514+
:::moniker-end
515+
516+
:::moniker range="< aspnetcore-9.0"
517+
518+
![The default retry UI.](signalr/_static/retry-ui-80-or-earlier.png)
519+
520+
:::moniker-end
521+
522+
If reconnection succeeds, user state is often lost. Custom code can be added to any component to save and reload user state across connection failures. For more information, see <xref:blazor/state-management>.
495523

496524
:::moniker range=">= aspnetcore-8.0"
497525

498-
To customize the UI, define a single element with an `id` of `components-reconnect-modal`. The following example places the element in the `App` component.
526+
To customize the UI, define a single element with an `id` of `components-reconnect-modal` in the `<body>` element content. The following example places the element in the `App` component.
499527

500528
`App.razor`:
501529

502530
:::moniker-end
503531

504532
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"
505533

506-
To customize the UI, define a single element with an `id` of `components-reconnect-modal`. The following example places the element in the host page.
534+
To customize the UI, define a single element with an `id` of `components-reconnect-modal` in the `<body>` element content. The following example places the element in the host page.
507535

508536
`Pages/_Host.cshtml`:
509537

510538
:::moniker-end
511539

512540
:::moniker range=">= aspnetcore-6.0 < aspnetcore-7.0"
513541

514-
To customize the UI, define a single element with an `id` of `components-reconnect-modal`. The following example places the element in the layout page.
542+
To customize the UI, define a single element with an `id` of `components-reconnect-modal` in the `<body>` element content. The following example places the element in the layout page.
515543

516544
`Pages/_Layout.cshtml`:
517545

518546
:::moniker-end
519547

520548
:::moniker range="< aspnetcore-6.0"
521549

522-
To customize the UI, define a single element with an `id` of `components-reconnect-modal`. The following example places the element in the host page.
550+
To customize the UI, define a single element with an `id` of `components-reconnect-modal` in the `<body>` element content. The following example places the element in the host page.
523551

524552
`Pages/_Host.cshtml`:
525553

526554
:::moniker-end
527555

528556
```cshtml
529557
<div id="components-reconnect-modal">
530-
There was a problem with the connection!
558+
Connection lost.<br>Attempting to reconnect...
531559
</div>
532560
```
533561

@@ -557,6 +585,15 @@ Add the following CSS styles to the site's stylesheet.
557585
#components-reconnect-modal.components-reconnect-failed,
558586
#components-reconnect-modal.components-reconnect-rejected {
559587
display: block;
588+
background-color: white;
589+
padding: 2rem;
590+
border-radius: 0.5rem;
591+
text-align: center;
592+
box-shadow: 0 3px 6px 2px rgba(0, 0, 0, 0.3);
593+
margin: 50px 50px;
594+
position: fixed;
595+
top: 0;
596+
z-index: 10001;
560597
}
561598
```
562599

@@ -581,7 +618,7 @@ Customize the delay before the reconnection UI appears by setting the `transitio
581618

582619
:::moniker-end
583620

584-
:::moniker range="< aspnetcore-8.0"
621+
:::moniker range=">= aspnetcore-5.0 < aspnetcore-8.0"
585622

586623
`wwwroot/css/site.css`:
587624

@@ -606,11 +643,9 @@ To display the current reconnect attempt, define an element with an `id` of `com
606643
</div>
607644
```
608645

609-
When the custom reconnect modal appears, it renders content similar to the following based on the preceding code:
646+
When the custom reconnect modal appears, it renders the following content with a reconnection attempt counter:
610647

611-
```html
612-
There was a problem with the connection! (Current reconnect attempt: 3 / 8)
613-
```
648+
> :::no-loc text="There was a problem with the connection! (Current reconnect attempt: 1 / 8)":::
614649
615650
:::moniker-end
616651

13.7 KB
Loading
11.8 KB
Loading
19 KB
Loading
15.2 KB
Loading

0 commit comments

Comments
 (0)