havit/Havit.Blazor

[doc] GatewayToPremium - Skip this page next time - the page is not skipped

Closed this issue · 3 comments

Does not work as expected
cc @Harvey1214

@hakenr it did work as expected. <PageCanonicalUrl> was intentionally set up not to render the wrapping <HeadContent> as to minimize the number of errors caused by multiple HeadContents on one page.

This doubled rendering introduced in this commit led to the error. Should be fixed in the linked PR.

@Harvey1214, both features have issues:

  1. The <PageCanonicalUrl> with HeadContent assumes it's the only <HeadContent> provider (since HeadOutlet doesn’t merge multiple HeadContent instances - the "last wins" rule applies), which is too restrictive.
  2. The GatewayToPremium injects a <script> tag directly into the existing page, which isn’t supported in Blazor. Even Static SSR requires careful handling: https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/static-server-rendering?view=aspnetcore-8.0, check out the new HxToast implementation for reference.

We need to address this on both sides:

  1. The <PageCanonicalUrl> should be modified to avoid blocking other <head> extensions while keeping the usage simple. I’m planning to change it to something like <MetadataHeadContent>, allowing additional head content to be appended.

  2. The GatewayToPremium needs a Blazor-compatible approach for the entire flow. Let's split the scenario into two steps:

    1. The URL /premium/access-content?url=... will be handled by the server (controller only). Based on whether a cookie is present in the request, it will either redirect the user to the target URL immediately (without involving Blazor on the server or client) or redirect the user to:
    2. A second Blazor server URL with the GatewayToPremium content (let's use a URL like /premium/access-content-gateway?url=...).

From our in-person discussion:

  • Instead of using the controller, we can handle the redirect during component server prerendering.
  • We’ll merge steps i. and ii. above into a single Blazor component. This component will perform a cookie check and optionally handle the server redirect during prerendering. For WASM interactive rendering, it will use a JS getSkipCookieValue function, along with NavigationManager.NavigateTo() based on the result.