Skip to content
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

[Bug] LocalStorage crashes without throwing exception #219

Closed
sponsorrockit opened this issue Aug 23, 2023 · 14 comments · Fixed by #247
Closed

[Bug] LocalStorage crashes without throwing exception #219

sponsorrockit opened this issue Aug 23, 2023 · 14 comments · Fixed by #247
Labels
Bug Something isn't working Needs: More Information The author needs to provide more information on the issue.

Comments

@sponsorrockit
Copy link

Describe the bug
local storage crashes with no exception thrown.
Was working fine until today. Suddenly stopped working without changes to code.

To Reproduce
Using SignalIR Blazor Server .Net 7

Any attempt to Get or Set item async crashes, stops all processing without error in jscript or error in blazor server.
await localStorage.GetItemAsync("systemUser");
await localStorage.SetItemAsync("systemUser", systemUser);

Expected behavior
An error message or exception

Hosting Model (is this issue happening with a certain hosting model?):

  • Blazor Server

Additional context
No Exception thrown, just stops all processing in OnAfterRenderAsync and OnInitializedAsync
Had to comment all lcoal storage uses: Was working fine until today then stopped without posting any code changes.
@Inject ILocalStorageService localStorage
// try
// {

// await localStorage.SetItemAsync("systemUser", systemUser);
// }
// catch (Exception e)
// {
// }
Screenshot 2023-08-23 15 06 51

@sponsorrockit sponsorrockit added Bug Something isn't working Triage Issue needs to be triaged labels Aug 23, 2023
@sponsorrockit
Copy link
Author

Browser details - no local storage error thrown just a disconnect from blazor server
Localstoragerror

@sponsorrockit sponsorrockit changed the title [Bug] [Bug] LocalStorage crashes without throwing exception Aug 23, 2023
@chrissainty
Copy link
Member

Hey @sponsorrockit, can you provide a minimal repro project, the package is working fine as far as a I can see testing on the sample projects and in a fresh project.

@chrissainty chrissainty added Needs: More Information The author needs to provide more information on the issue. and removed Triage Issue needs to be triaged labels Aug 24, 2023
@sponsorrockit
Copy link
Author

sponsorrockit commented Aug 24, 2023 via email

@sponsorrockit
Copy link
Author

sponsorrockit commented Aug 29, 2023 via email

@chrissainty
Copy link
Member

chrissainty commented Nov 1, 2023

Thanks for the detailed explanation @sponsorrockit.

Just to clarify, are you putting an object into local storage that contains 30+ other objects (your whole domain pretty much)? Just that you said you weren't happy sharing them here but anyone who uses your app will be able to get hold of them.

In terms of the issue you're seeing, it sounds like it might be a System.Text.Json problem. If you're saving one structure and then changing that structure and attempting to read it out again, it might need some extra configuration to handle that. It's not as forgiving as Newtonsoft JSON is. Have you tried adjusting the serialiser?

@julianadormon
Copy link

I am having a similar issue trying
var StoredFormModels = await LocalStorage.GetItemAsync<List>("Forms");

I have not been able to narrow it down yet, however what is truly the bigger issue is that even though this is wrapped in a try/catch, it never reaches the catch.

It simply fails silently and causes the web socket to refresh. No errors in console or server.

@julianadormon
Copy link

julianadormon commented Jan 16, 2024

@chrissainty I'm not sure if you had a chance to review my comment above. Any ideas on how we can get this to fail properly?

`async void SaveFormLocally()
{
try
{
if (PageVm.FormPageVm == null) return;

        PageVm.FormPageVm.CustomFormSubmission.DateSubmitted = DateTime.UtcNow;

        PageVm.FormPageVm.CustomFormSubmission.CustomFormId = PageVm.FormPageVm.CustomForm.CustomFormId;
        
        var StoredFormModels = await LocalStorage.GetItemAsync<List<CustomFormSubmission>>("ProofpixForms");

        if (StoredFormModels != null)
        {
            if (StoredFormModels.Any(x => x.CustomForm.CustomFormId == PageVm.FormPageVm.CustomFormSubmission.CustomForm.CustomFormId))
            {
                var StoredCustomFormSubmission = StoredFormModels.FirstOrDefault(x => x.CustomForm.CustomFormId == PageVm.FormPageVm.CustomFormSubmission.CustomForm.CustomFormId);

                if (StoredCustomFormSubmission != null)
                {
                    StoredFormModels.Remove(StoredCustomFormSubmission);
                }

                StoredFormModels.Add(PageVm.FormPageVm.CustomFormSubmission);
            }
            else
            {
                StoredFormModels.Add(PageVm.FormPageVm.CustomFormSubmission);
            }
        }
        else
        {
            StoredFormModels = new List<CustomFormSubmission> { PageVm.FormPageVm.CustomFormSubmission };
        }

        await LocalStorage.SetItemAsync("ProofpixForms", StoredFormModels);
    }
    catch (Exception Ex)
    {
        Console.WriteLine(Ex.ToString());
    }
}`

@adamhearn
Copy link

adamhearn commented Jan 17, 2024

@chrissainty .NET 8 Blazor wasm only project (bumped from and was working with 6) with the same issue as described. The version of LocalStorage is the same (4.4.0). Browser is Edge latest on Windows 10.

The call it gets down to is:

BrowserStorageProvider::GetItemAsync
return await _jsRuntime.InvokeAsync<string>("localStorage.getItem", cancellationToken, key);

Nothing raised, nothing logged in VS or the browser console just hangs there seemingly forever.

@adamhearn
Copy link

Also, swapped out this library for another and it exhibited the exact same issue. If it wasn't already obvious it's safe to say that it's a .NET 8 wasm issue rather than an issue with this library.

@julianadormon
Copy link

julianadormon commented Jan 18, 2024

I'm using Blazer Server .net 7 with System.Text.Json.
I ended up saving my data as strings and then serialize those to avoid the issue. Seems to be working so far.

@julianadormon
Copy link

Actually, I take that back. I am getting a socket reset with no error now calling:
var StoredFormStrings = await LocalStorage.GetItemAsync<List>("ProofpixForms");

@panoukos41
Copy link

panoukos41 commented Mar 7, 2024

After coming across this issue and having the same problem myself in Blazor Server .NET 6.0 & lib version 4.3.0 I get no exception and the connection just resets.

It must have something to do with the object size. Although the object ends up in the storage the connection just crushes. When I reduced the size of my object it worked fine. It didn't matter if I used the AsString or serialized it to a string myself.

@chrissainty
Copy link
Member

For Blazor Server, some people could be hitting the default limit of the SignalR connection. It's worth trying to up that and see if that cures the issues.

@panoukos41
Copy link

@chrissainty yes for server increasing the limit fixed the problem thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Needs: More Information The author needs to provide more information on the issue.
Projects
None yet
5 participants