Skip to content

blazor localStorage F5 Refresh “Object reference not set to an instance of an object.” #14162

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

Closed
scalablecory opened this issue Sep 19, 2019 · 2 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@scalablecory
Copy link
Contributor

From @azbo on Wednesday, September 18, 2019 6:31:28 AM

Issue Title

blazor localStorage F5 Refresh “Object reference not set to an instance of an object.”

General

visual studio version:
image

sdk version:.net core sdk 3.0 rc1

localStorage get set js:
image

Index.razor set localStorage:
image

Counter.razor get localStorage:
image

Reiteration steps:
step1: image

step2:
image

step3:
F5 Refresh or
image

step4 except:
image

Copied from original issue: dotnet/core#3394

@javiercn
Copy link
Member

javiercn commented Sep 20, 2019

@scalablecory You are trying to perform JS interop during OnInitializedAsync which is not supported and might not work well in all scenarios. The right place to do JS interop (where is safe to do so) is inside OnAfterRenderAsync

What is happening is that during prerendering the JS runtime is not initialized, so you get an error when you try to prerender the Counter page. It doesn't happen when you are launching the app because you are prerendering the Index page, but when you go to the counter page and press F5 it tries to prerender the Counter page and fails at that point.

@pranavkm
Copy link
Contributor

@azbo this is a dup of #13396. We'll use the other issue to track fixing this in 3.1. In the meanwhile, @javiercn's recommendation is correct.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

3 participants