Skip to content

Cannot read properties of undefined reading 'filter' in control-sharing example #4314

@michalkotas

Description

@michalkotas

Problem

Error message when running runtime-plugins/control-sharing example:

Uncaught TypeError: Cannot read properties of undefined (reading 'filter')

Cause

  • control-share assumes that instance.options.shared[pkgName] is object, not an array of object
  • typo in js version of control-share - store.name versus runtimeStore.store

Workaround

Use runtimeStore variable, use options.shared[pkgName] as array, stick to index 0

      args.resolver = function () {
        if (!overrides[runtimeStore.name]) {
          return originalResolver();
        }

        const overrideVersion = overrides[runtimeStore.name][pkgName];
        const matchingInstance = GlobalFederation.__INSTANCES__.find(instance => {
          return instance.options.shared[pkgName].some(
            sharedPackage => sharedPackage.version === overrideVersion,
          );
        });

        if (matchingInstance) {
          const current = shareScopeMap[scope][pkgName][version],
            override = matchingInstance.options.shared[pkgName][0]; //TODO: which element should i pick?
          if (current.from === override.from) return current;
          const originInstance = GlobalFederation.__INSTANCES__.find(instance => {
            return instance.options.name === current.from;
          });
          originInstance.options.shared[pkgName].forEach(sharedPackage => {
            sharedPackage.useIn.filter(i => i !== runtimeStore.name);
          });
          shareScopeMap[scope][pkgName][version] = matchingInstance.options.shared[pkgName][0]; //TODO: which element should i pick?

          if (!shareScopeMap[scope][pkgName][version].useIn.includes(runtimeStore.name)) {
            shareScopeMap[scope][pkgName][version].useIn.push(runtimeStore.name);
          }
          return matchingInstance.options.shared[pkgName][0]; //TODO: which element should i pick?;
        } else {
          console.log('No matching instance found for overrideVersion', overrideVersion);
        }

        return originalResolver();
      };
      return args;
    },

Question

How to determine correct index in options.shared[pkgName]?

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