Skip to content
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

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

Open
michalkotas opened this issue Nov 22, 2024 · 1 comment

Comments

@michalkotas
Copy link

michalkotas commented Nov 22, 2024

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]?

@ScriptedAlchemy
Copy link
Member

I have updated this example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants