Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update ResourceCollectionProvider to take advantage of Declarative persistent component state #61748

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ilonatommy
Copy link
Member

Follow-up for #60634.

Description

ResourceCollectionUrl saving and restoring responsibility is moved to PersistentServicesRegistry.

@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label Apr 30, 2025
@ilonatommy ilonatommy self-assigned this Apr 30, 2025
@ilonatommy ilonatommy requested a review from a team as a code owner April 30, 2025 12:37
Comment on lines +17 to +21
public string? ResourceCollectionUrl
{
get => _url;
set => _url = value;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public string? ResourceCollectionUrl
{
get => _url;
set => _url = value;
}
public string? ResourceCollectionUrl { get; set; }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather go towards removing SetResourceCollectionUrl and moving the exception logic into the setter. This can be done after the bug of preserving the values is found and fixed.

@ilonatommy
Copy link
Member Author

@javiercn, is it possible that we are not restoring the state for webassembly interactive at all? We have it done for server when the circuit is set up:

await appLifetime.RestoreStateAsync(store);

but I cannot find any RestoreStateAsync calls in wasm render mode context?

is the only one but it's not triggered on "rehydration" after prerendering.

@javiercn
Copy link
Member

javiercn commented May 6, 2025

@ilonatommy not sure what's going on here, but we have tests covering this.

You could try debugging the sample project to figure out what is going on

@ilonatommy
Copy link
Member Author

ilonatommy commented May 7, 2025

Summary what's going on:

Key in prerendering for Microsoft.AspNetCore.Components.ResourceCollectionProvider.ResourceCollectionUrl is different than the key for WASM rendering.

There are 2 reasons I suspect:

  • ResourceCollectionProvider is defined in "shared", so in prerendering it belongs to Microsoft.AspNetCore.Components.Endpoints assembly and in WASM rendering it belongs to Microsoft.AspNetCore.Components.WebAssembly.
  • version string differs between prerendering and WASM, Version=10.0.0.0 vs Version=42.42.42.42 (dummy version for WASM assemblies) and PublicKeyToken.

Even if we skip the version by using simplified name keyType.Assembly.GetName().Name instead of keyType.Assembly.FullName, the problem with changing assembly name on the rendering boundary persists.

Logs for using the simplified assembly name:

[ComputeKey] Using assembly: Microsoft.AspNetCore.Components.Endpoints, type: Microsoft.AspNetCore.Components.ResourceCollectionProvider, propertyName: ResourceCollectionUrl, inputString: Microsoft.AspNetCore.Components.Endpoints.Microsoft.AspNetCore.Components.ResourceCollectionProvider.ResourceCollectionUrl
[ComputeKey] computed key: reRoeSH0zUNg1lV5T25mU63ifKBQDmwekOTpUjGhOzw=
[Persist] Persisting Key: reRoeSH0zUNg1lV5T25mU63ifKBQDmwekOTpUjGhOzw= for Declared type: Microsoft.AspNetCore.Components.ResourceCollectionProvider, Runtime type: Microsoft.AspNetCore.Components.ResourceCollectionProvider Value: ./_framework/resource-collection.7sl7m.js

MonoPlatform.ts:234 [ComputeKey] Using assembly: Microsoft.AspNetCore.Components.WebAssembly, type: Microsoft.AspNetCore.Components.ResourceCollectionProvider, propertyName: ResourceCollectionUrl, inputString: Microsoft.AspNetCore.Components.WebAssembly.Microsoft.AspNetCore.Components.ResourceCollectionProvider.ResourceCollectionUrl
MonoPlatform.ts:234 [ComputeKey] computed key: OJ5IulA9AwVvEZZuXoXvRFiqSKythSxVh7f6TDMswl4=
MonoPlatform.ts:234 [Restore] Failed restoring Key OJ5IulA9AwVvEZZuXoXvRFiqSKythSxVh7f6TDMswl4= for Declared type: Microsoft.AspNetCore.Components.ResourceCollectionProvider, Runtime type: Microsoft.AspNetCore.Components.ResourceCollectionProvider.

@javiercn
Copy link
Member

javiercn commented May 7, 2025

@ilonatommy good catch.

This is something that we solved for other types (AntiforgeryStateProvider) relying on the public abstraction, but I don't think we want to add a public abstraction for this type, as it's completely internal.

We should figure out what we want to do here, but there are some options like explicitly providing a key in these cases where stuff is "shared".

We want to support passing information across boundaries without having to require any public API, we just need to tweak the way we do this.

I think we still want to use the full name to compute the key by default as that's the common case and guarantee's us that we don't squat over types that have the same name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants