Open Closed

Blazor WebApp RequersFeature() hide components from menu even if the feature is true by default #10138


User avatar
0
samirmustafayev created

Hi Abp Team,

I am having an issue with the Features in moduled Blazor Web Application. I have a nuget package wich contains FeatureDefenitionProvider for Groups where defenition provider is located in Domain layer and class for const name in Domay.Shared layer, i am using this groups in my modules to control them by features, by default they are true. When i start programm at first every component that is using RequersFeature() are visible, but then disapears on complete program load. As I understand server can see and detect them thas why it visible but when blazor client loads it make them disapear and in abp/application-configuration/feature:values there is no my custom features. My groups are in database with default values and in UI Settings:FeaturesManagement: groups and children are also visible and working. For example i will show featuresdefenition provider for Saas: Domain

using Payhas.Billing.Platform.Localization;
using Payhas.Common.Features; // this is the nuget package
using Volo.Abp.Features;
using Volo.Abp.Localization;

namespace Payhas.Billing.Platform.Features;

public class SaasFeaturesDefinitionProvider : FeatureDefinitionProvider
{
    public override void Define(IFeatureDefinitionContext context)
    {
        var mainModuleGroup = context.GetGroupOrNull(ModulesFeatures.Main);

        mainModuleGroup?.AddFeature(SaasFeatures.Saas,
           defaultValue: "true",
           L(SaasFeatures.Saas));
    }

    private static LocalizableString L(string name)
    {
        return LocalizableString.Create<PlatformResource>("Features:" + name);
    }
}

DomainShared:

using Payhas.Common.Features;
using Volo.Abp.Reflection;

namespace Payhas.Billing.Platform.Features;

public class SaasFeatures
{
    public const string Saas = ModulesFeatures.Main + ".Saas";

    public static string[] GetAll()
    {
        return ReflectionHelper.GetPublicConstantsRecursively(typeof(SaasFeatures));
    }
}

Blazor.Client: Navigation MenuContributor

//Saas
 var saas = context.Menu.GetMenuItem(SaasHostMenus.GroupName);
 saas.RequireFeatures(SaasFeatures.Saas);

<br>


10 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution
    • Root cause

      • In Blazor Web App, menus are built on the server first, then the client (WASM-side) re-hydrates and re-evaluates feature/permission requirements using values coming from the Application Configuration endpoint. If your custom feature definitions are not exposed to the client, RequireFeatures(...) will hide items after client load.
      • Features are only sent to the client if each feature definition:
        • Belongs to a registered Feature Group, and
        • Is visible to clients (IsVisibleToClients = true), and
        • The FeatureDefinitionProvider is discovered in the running app (module dependency path).
    • What to do

      1. Ensure your FeatureDefinition is visible to clients
    public class SaasFeaturesDefinitionProvider : FeatureDefinitionProvider
      {
          public override void Define(IFeatureDefinitionContext context)
          {
              var group = context.GetGroupOrNull(ModulesFeatures.Main)
                         ?? context.AddGroup(ModulesFeatures.Main, L("MainFeatures"));
    
              group.AddFeature(
                  SaasFeatures.Saas,
                  defaultValue: "true",
                  displayName: L(SaasFeatures.Saas),
                  isVisibleToClients: true // <<< important
              );
          }
    
          private static LocalizableString L(string name)
              => LocalizableString.Create<PlatformResource>("Features:" + name);
      }
    
    1. Make sure the Feature Group exists in the same Define call path
    • If your ModulesFeatures.Main group is defined in a shared NuGet, ensure that group is created before adding features. If not already created in that package, add it as shown above with context.AddGroup(...).
    1. Verify the module dependency path so the provider is discovered
    • The assembly that contains SaasFeaturesDefinitionProvider must be referenced and its module must be depended on by the application:
    [DependsOn(
          typeof(AbpFeaturesModule)
          // + your package/module that contains the FeatureDefinitionProvider
      )]
      public class PlatformDomainModule : AbpModule
      {
      }
    
    • Ensure the package is referenced by the final app (HttpApi.Host for server, and the Blazor project if it needs types). The provider must be in a module that is part of the server app’s module graph so the server can define and expose features.
    1. Do not mark the feature as not visible later
    • Avoid setting IsVisibleToClients = false anywhere via options or additional providers.
    1. Confirm from the client that the feature is delivered
    • After the above changes, the application-configuration response should include your feature under features.values.
    • If it still doesn’t appear, clear caches and ensure you’ve run the migrator and restarted the app.
    1. Using RequireFeatures on the menu
    • With the feature now visible to clients, the item will remain visible after client load:
    var saas = context.Menu.GetMenuItem(SaasHostMenus.GroupName);
      saas.RequireFeatures(SaasFeatures.Saas);
    
    1. Notes on defaultValue and database values
    • defaultValue: "true" is used only if there is no stored value. If you manage the feature in UI, the database value takes precedence.

    • Ensure the tenant/host you are testing has the feature enabled in the Features modal.

    • Quick checklist

      • [ ] Feature group exists (context.AddGroup or previously defined).
      • [ ] AddFeature(... isVisibleToClients: true).
      • [ ] Provider assembly is loaded and module is in dependency chain.
      • [ ] application-configuration features.values contains your key.
      • [ ] Menu item uses RequireFeatures with the correct full feature name.
    1. Sources
    • Features basics and client visibility:
      • https://github.com/abpframework/abp (project source reference)
      • This approach aligns with the official “Features” documentation statement: “A feature value is available at the client side too, unless you set IsVisibleToClients to false on the feature definition.”

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Is your webapp tiered?

    abp/application-configuration/

    Does this endpoint's website depend on your feature definition package?


    How can I reproduce this problem in a new webapp template project?

    Can you share the code and steps?

    liming.ma@volosoft.com

    Thanks.

  • User Avatar
    0
    samirmustafayev created

    Main project is WASM but modules are Blazor server (they do not have blazorClient). Main project and modules are tiered. Does this endpoint's website depend on your feature definition package? Answers : yes, FeatureManagement modules installed.

    Nuget package was made from moduled Blazor WASM project from one of the modules for example Module#2 . MainProject (tiered) Module#1 => (feature groups were added DefinitionProvider) (tiered) Module#2 => (DependsOn Module#1 using adding features to the featureGroup) (tiered) Module#3 => (DependsOn Module#1 using adding features to the featureGroup) (tiered) Module#4 => (DependsOn Module#1 using adding features to the featureGroup) (tiered)

    Created New Blazor Wasm moduled tiered project where modules are Blazor server , cause there no BlazorClient. In Domain added FeatureDefenitionProvider with GetGroupOrNull and added feature with default true. In DomainShared added constant for features name to use in BlazorClient MenuContributor class for menu item that RequersFeature().

    In database AbpFeatureGroups table the custom added groups are there, also in Administration-Settings-FeatureManagment: FeatureGroups are visible and they functionaly working but in menu they are disappeared

  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution
    • Why it happens

      • In Blazor Web App (WASM + Server), the initial prerender builds the menu on the server with server-side feature values. When the WASM client hydrates, it replaces the menu using feature values coming from the application-configuration endpoint. If your custom features are not included in that payload, any menu items with RequireFeatures(...) will be hidden after hydration.
    • Fix step-by-step

      1. Make features visible to the client
      • Define your features with isVisibleToClients: true. Also ensure the feature group exists before adding features.
    public class SaasFeaturesDefinitionProvider : FeatureDefinitionProvider
      {
          public override void Define(IFeatureDefinitionContext context)
          {
              var group = context.GetGroupOrNull(ModulesFeatures.Main)
                         ?? context.AddGroup(ModulesFeatures.Main, L("MainFeatures"));
    
              group.AddFeature(
                  SaasFeatures.Saas,
                  defaultValue: "true",
                  displayName: L(SaasFeatures.Saas),
                  isVisibleToClients: true // critical for WASM menu visibility
              );
          }
    
          private static LocalizableString L(string name)
              => LocalizableString.Create<PlatformResource>("Features:" + name);
      }
    
    1. Ensure the provider is discovered by the server that serves abp/application-configuration
    • The assembly that contains SaasFeaturesDefinitionProvider must be part of the HttpApi.Host (or the Blazor Web App server host) module graph.
    • Add module dependency to the host’s Domain module (and reference the NuGet/assembly):
    [DependsOn(
          typeof(AbpFeaturesModule),
          typeof(Payhas.Common.FeaturesModule) // your package/module that defines groups & features
      )]
      public class PlatformDomainModule : AbpModule
      {
      }
    
    • The server project must reference the NuGet/Project so ABP scans the FeatureDefinitionProvider at startup.
    1. Verify the feature actually reaches the client
    • After running, check the response of:
      • GET /abp/application-configuration?IncludeLocalizationResources=true
    • Under features.values you should see an entry for "ModulesFeatures.Main.Saas" (or your full name). If it’s missing, the client will hide your menu item.
    • If missing:
      • Restart the server after adding the provider and dependencies.
      • Ensure IsVisibleToClients is true.
      • Ensure the current side (host/tenant) has the feature enabled. Default values are used only when no stored value exists.
    1. Use RequireFeatures on menu items (unchanged on your side)
    var saas = context.Menu.GetMenuItem(SaasHostMenus.GroupName);
      saas.RequireFeatures(SaasFeatures.Saas);
    
    1. Notes for tiered WASM + Server modules
    • It’s fine that modules are “Blazor Server” only. What matters is that the server host contains the feature definition provider in its module dependency chain so that the Application Configuration endpoint can include your features.
    • If your feature groups are defined in a shared NuGet, ensure that NuGet is referenced by the host and the module exposing the FeatureDefinitionProvider depends on it so context.AddGroup/GetGroupOrNull targets the same group name.
    1. Caching tip (only if values change and you don’t see updates)
    • The client reads features from the Application Configuration endpoint, which is cached by default on the client side. Reloading the page after changing features is typically enough; server-side feature store uses distributed cache. Ensure your distributed cache (e.g., Redis) is correctly configured in all services that participate.

    • Expected outcome

      • With isVisibleToClients: true and the provider included in the host’s module graph, your custom feature appears in application-configuration.features.values and the menu items protected by RequireFeatures(...) will remain visible after WASM hydration.
    1. Sources
    • Features and client visibility:
      • https://docs.abp.io/en/abp/latest/Features
    • ABP Module system:
      • https://abp.io/docs/latest/framework/architecture/modularity/basics

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    samirmustafayev created

    I could not find solution for the issue that I have

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    If you have a MyDefinitionProvider class. Your api website(consumed by wasm) has to depend on it.

    Thanks,.

  • User Avatar
    0
    samirmustafayev created

    Any suggestions on this issue, cause dependency is there. Signa R getting the features but by http api it does not?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi @samirmustafayev

    Any website that needs to check features must directly or indirectly reference the module that defines the MyDefinitionProvider class.

    Thanks.

  • User Avatar
    0
    samirmustafayev created

    Hi I figured it out. the problem was not in the features. We using RenderdMode so BlazorClient configured to RemoteServer which is the BlazorServer not HttpApiHost.

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great 👍

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on December 12, 2025, 10:36
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.