Skip to content

No singleton service #97

Description

@dr460nf1r3

Hi!

The new native federation version looks pretty good, and its very fast. However, with the version it looks like sharedMappings are no longer singleton, or something prevents it from working like before. The loading service we have not working anymore, which seems to be the case because the subscription to loading state lives on a separate instance of the service (it only ever receives the initial false and then never again). This is already the case in the shell, not even in the micro frontend. It looked like the service is injected twice, even though it should be a singleton instance. I found it weird that it is seemingly in the shared mapping and the bootstrap as well:

loading-indicator.service.ts:16 [LoadingIndicatorService] INSTANCE CREATED #1 Error
    at new _LoadingIndicatorService (http://localhost:4200/_somelib.js:119862:83)
    at Object.LoadingIndicatorService_Factory [as factory] (http://localhost:4200/_somelib.js:119885:14)
    at http://localhost:4200/chunk-FXF3KUBP.js:1340:47
    at runInInjectorProfilerContext (http://localhost:4200/chunk-FXF3KUBP.js:409:9)
    at R3Injector.hydrate (http://localhost:4200/chunk-FXF3KUBP.js:1338:21)
    at R3Injector.get (http://localhost:4200/chunk-FXF3KUBP.js:1218:33)
    at R3Injector.retrieve (http://localhost:4200/chunk-FXF3KUBP.js:1129:25)
    at injectInjectorOnly (http://localhost:4200/chunk-FXF3KUBP.js:676:39)
    at ɵɵinject (http://localhost:4200/chunk-FXF3KUBP.js:688:61)
    at inject (http://localhost:4200/chunk-FXF3KUBP.js:697:12)
...
loading-indicator.service.ts:16 [LoadingIndicatorService] INSTANCE CREATED #1 Error
    at new _LoadingIndicatorService (http://localhost:4200/bootstrap-LYF4SCVX.js:136:83)
    at Object.LoadingIndicatorService_Factory [as factory] (http://localhost:4200/bootstrap-LYF4SCVX.js:159:14)
    at http://localhost:4200/chunk-FXF3KUBP.js:1340:47
    at runInInjectorProfilerContext (http://localhost:4200/chunk-FXF3KUBP.js:409:9)
    at R3Injector.hydrate (http://localhost:4200/chunk-FXF3KUBP.js:1338:21)
    at R3Injector.get (http://localhost:4200/chunk-FXF3KUBP.js:1218:33)
    at ChainedInjector.get (http://localhost:4200/_angular_core.HquQGppmK0-dev.js:8244:36)
    at lookupTokenUsingModuleInjector (http://localhost:4200/_angular_core.HquQGppmK0-dev.js:588:39)
    at getOrCreateInjectable (http://localhost:4200/_angular_core.HquQGppmK0-dev.js:613:12)
    at ɵɵdirectiveInject (http://localhost:4200/_angular_core.HquQGppmK0-dev.js:8851:19)

Federation config:

import { share, withNativeFederation } from '@angular-architects/native-federation/config';

export default withNativeFederation({
  name: 'shell',

  shared: {
    ...share({
      '@angular/core': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
        includeSecondaries: { keepAll: true },
      },
      '@angular/common': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
        includeSecondaries: { keepAll: true },
      },
      '@angular/common/http': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
      },
      '@angular/common/locales/de': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
      },
      '@angular/common/locales/en': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
      },
      '@angular/router': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
      },
      '@angular/forms': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
      },
      '@angular/platform-browser': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
      },
      '@angular/platform-browser-dynamic': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
      },
      '@jsverse/transloco': {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
      },
      rxjs: {
        singleton: true,
        strictVersion: true,
        requiredVersion: 'auto',
      },
    }),
  },

  sharedMappings: ['somelib'],

  features: {
    ignoreUnusedDeps: true,
  },
});

Happy to provide more information if required!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions