AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Configuring Stateful Reconnect

Open CePur opened this issue 1 year ago • 3 comments

Description

[Enter feedback here]

Hi, trying stateful reconnect but js throws this exception "(intermediate value).withUrl(...).withStatefulReconnect is not a function". Using https://unpkg.com/browse/@microsoft/[email protected]/

Page URL

https://learn.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-8.0&tabs=dotnet#configure-stateful-reconnect

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/signalr/configuration.md

Document ID

66d252c3-6300-7e28-9aa0-ef2ff66e7a76

Article author

@bradygaster

CePur avatar Jan 15 '24 16:01 CePur

@CePur, thanks for taking the time to let us know your experience with this doc. I will cue this doc up to be retested. In the meantime, it would be good to verify the following isn't happening that could result in that error: Take a look at the .csproj file of your project and note if you are still referencing an old Microsoft.AspNetCore.SignalR.Client.Core. There should not be one in there. Instead, it should be Microsoft.AspNetCore.SignalR.Client and it should be the latest version you were already mentioning. Please let me know if that turns out to be what was happening. Thanks again!

wadepickett avatar Jan 15 '24 20:01 wadepickett

@wadepickett i don't directly reference it so there is no Microsoft.AspNetCore.SignalR.Client in .csproj. Project is asp.net web project <Project Sdk="Microsoft.NET.Sdk.Web"> targeting net8.0

CePur avatar Jan 16 '24 08:01 CePur

Thanks for the insight!

wadepickett avatar Jan 16 '24 19:01 wadepickett

@BrennanConroy

With the following set in Program.CS for stateful reconnect: builder.Services.AddSignalR(o => o.StatefulReconnectBufferSize = 1000);

and

app.MapHub<ChatHub>("/chatHub", options =>
{
    options.AllowStatefulReconnects = true;
});`

The example we had in there for a JavaScript Client was the following:

const builder = new signalR.HubConnectionBuilder()
  .withUrl("/hubname")
  .withStatefulReconnect({ bufferSize: 1000 });  // Optional, defaults to 100,000
const connection = builder.build();

But that example currently in the doc does indeed result in a runtime error that does not recognize withStatefulReconnect as a function: TypeError: (intermediate value).withUrl(...).withStatefulReconnect is not a function.

Looking in the latest js unpkg package as it downloads (@microsoft/[email protected]) the option .withStatefulReconnect() does not exist so the error makes sense. It is not in there, but that is the latest version you get. Maybe the 8.0 updates did not actually get into that unpkg package?

However, I do see .withStatefulReconnect() defined here: https://unpkg.com/@microsoft/[email protected]/src/HubConnectionBuilder.ts

Am I somehow getting the wrong js package, or the call to HubConnectionBuilder, or for a JavaScript client should I be doing something different such as:

var connection = new signalR.HubConnectionBuilder()
    .withUrl("/chatHub")
    .withAutomaticReconnect()
    .build();

I'll update this doc and the What's new for .NET 8 that had the same example with whatever the correction should be. I'm not sure what the correct client setting should be though.

wadepickett avatar Mar 27 '24 00:03 wadepickett

@BrennanConroy, I'm hoping you might be able to take a look a this above. I would have to get the fix in today to get a review in time for this sprint. Sorry to ask, I looked through the source and all related issues and the end result SignalR.js. I'm not able to get it to work as intended.

wadepickett avatar Mar 28 '24 16:03 wadepickett

The function does exist, look at line 3474 of https://unpkg.com/browse/@microsoft/[email protected]/dist/browser/signalr.js

I'm guessing they aren't using an 8.0 version of the library.

BrennanConroy avatar Apr 01 '24 03:04 BrennanConroy

Thanks @BrennanConroy. Could you check a new download through the VS libman using unpkg for browser/signalr.js for 8.0.0 or "latest"? I see it on the unpkg site as you pointed out. However, when I add it through Visual Studio using the Library Manager for unpkg and I either specify "latest" or "8.0.0" I receive a version that does not have the word "stateful" anywhere in browser/signalr.js

image

Here is what lines 1177 - 1181 should have in it:

image

The downloaded 8.0.0 signalr.js however is missing the const for DEFAULT_STATEFUL_RECONNECT_BUFFER_SIZE: image

withServerTimeout(), withKeepAliveInterval() and withStatefulReconnect()should be defined right after withAutomaticReconnect() starting on line 3456 through 3481.
However, in the downloaded 8.0.0 signalr.js through libman for unpkg, those 3 are missing. After withAutomaticReconnect() is defined, then comes build() right after:

image

Should I file a tracking issue? Maybe it is cache issue on unpkg for 8.0.0 or it was not propagated across all their servers?

I checked I also checked jsdelivr, that service for 8.0.0 is fine, withStatefulReconnect and the other new functions are in there as expected.

wadepickett avatar Apr 05 '24 18:04 wadepickett

Could you check a new download through the VS libman using unpkg for browser/signalr.js for 8.0.0

Just tried, it has the stateful reconnect code.

BrennanConroy avatar Apr 05 '24 18:04 BrennanConroy

Interesting. I must be doing something goofy on this end. I get 8.0.0 for jsdelivr just fine, for unpkg 8.0.0 shows up selectable and downloads, but the actual download that arrives is a version before 8.0.0 without stateful reconnect. I started with new projects each test and reboot VS. I have the latest VS. This issue is just for unpkg for me when using libman on VS.

Maybe I am getting a particular server on the farm for unpkg and re-hitting it? That seems slim though, so must be something I am missing on my end given you are not able to recreate. Thanks.

wadepickett avatar Apr 05 '24 19:04 wadepickett

Closing since not a doc issue to update here after testing it out.

wadepickett avatar Apr 05 '24 19:04 wadepickett

I believe i found the issue. For future wanderers:

https://github.com/aspnet/LibraryManager/issues/640#issuecomment-2086157971

CePur avatar Apr 30 '24 17:04 CePur

Awesome, thanks @CePur!

wadepickett avatar May 01 '24 04:05 wadepickett