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

PubSub already loaded console warning #124

Open
Tracked by #688
adamstankiewicz opened this issue Sep 2, 2022 · 10 comments
Open
Tracked by #688

PubSub already loaded console warning #124

adamstankiewicz opened this issue Sep 2, 2022 · 10 comments
Assignees

Comments

@adamstankiewicz
Copy link
Member

adamstankiewicz commented Sep 2, 2022

In @edx/frontend-platform, running the tests, there are many console warnings about "PubSub already loaded, using existing version". These console warnings can also be seen in some MFE test suites, as well.

PASS src/initialize.test.js
  ● Console
    console.warn
      PubSub already loaded, using existing version
      18 |  */
      19 |
    > 20 | import PubSub from 'pubsub-js';
         | ^
      21 |
      22 | /**
      23 |  *
      at node_modules/pubsub-js/src/pubsub.js:15:17
      at Object.<anonymous> (node_modules/pubsub-js/src/pubsub.js:35:2)
      at Object.<anonymous> (src/pubSub.js:20:1)
PASS src/analytics/interface.test.js

AC

  • Identify what's causing the console warnings about PubSub already being loaded.
  • Fix so that there are no more console warnings about PubSub already being loaded.
@adamstankiewicz adamstankiewicz moved this to Todo in FED-BOM Sep 2, 2022
@abdullahwaheed abdullahwaheed moved this from Todo to In Progress in FED-BOM Sep 7, 2022
@BilalQamar95 BilalQamar95 moved this from In Progress to Todo in FED-BOM Sep 12, 2022
@BilalQamar95 BilalQamar95 self-assigned this Sep 19, 2022
@abdullahwaheed abdullahwaheed moved this from Todo to In Progress in FED-BOM Oct 6, 2022
@ishahroz
Copy link

When running the test cases, these console warnings come as a result of the singleton pattern being used in the PubSub package. According to this PR, it gives information on if PubSub is already initialised on the root level, that root instance should be used instead of overriding with an empty new one.

After doing root cause analysis, I could pull some of the following observations:

  1. These console warnings only come when running the following test suites in @edx/frontend-platform:
  • src/initialize.test.js
  • src/react/AuthenticatedPageRoute.test
  1. In both these test suites, we find common auth interface being imported src/auth/interface.js, and which indirectly imports and employs PubSub module.

  2. After removing PubSub wrapper import (import { publish } from '../pubSub') from src/auth/interface.js, we no longer get to see these console warnings.

  3. But removing so, it will create ripple since we are using publish method in some of src/auth/interface.js methods. So, to incorporate the removed lines, I wrote their implementation in src/auth/MockAuthService.js but in turn, we get to see the same console warnings after running the test cases.

Moreover, these console warnings merely provide information to reinforce singleton use of PubSub. Maybe instead of passing this information as console warning, it should be documented or set lower message priority level.

Repository owner moved this from Needs refinement to In progress in Frontend Working Group Oct 14, 2022
Repository owner moved this from In Progress to Done in FED-BOM Oct 14, 2022
@ishahroz ishahroz reopened this Oct 14, 2022
@arbrandes
Copy link

(/me wears Community Project Manager hat.) @adamstankiewicz, thoughs on @ishahroz's findings?

@adamstankiewicz
Copy link
Member Author

@ishahroz Thanks for investigating. It'd be great if we could set it as a lower message priority level; however, we don't control the code that's generating the console warning. Documentation won't really help reduce the noise in the test output in consuming applications.

[clarification] It's not just the tests in @edx/frontend-platform itself that throw the warning. We are seeing the "PubSub already loaded" console warning when running tests for components that consume @edx/frontend-platform in separate micro-frontend repositories. Generally, we see one warning per test file that consumes @edx/frontend-platform, which adds a lot of unnecessary noise to the test output and sometimes makes it seem like tests are failing when they aren't (e.g., in frontend-app-admin-portal, we have over 200 test files and see this console warning for nearly all of them).

For what it's worth, I noticed there's an existing PR up for pubsub-js around disabling the console.warn. I added notes about our issue as a comment here, with links to @edx/frontend-platform's source and additional example warning stack traces.

/cc @arbrandes

@arbrandes
Copy link

I'm marking this as "Blocked" in the Frontend Dev board. In particular, on the upstream merge of the PR @adamstankiewicz pointed out.

@arbrandes
Copy link

Upstream commented on the PR:

mroderick/PubSubJS#220 (comment)

@adamstankiewicz, @ishahroz, what are your takes?

@arbrandes
Copy link

@adamstankiewicz, @ishahroz: ping! See above comment: looks like upstream reacted.

@adamstankiewicz
Copy link
Member Author

adamstankiewicz commented Jan 23, 2023

@arbrandes @ishahroz I've responded to the upstream comment, and agree that utilizing a PUBSUBJS_DISABLE_EXISTING_VERSION_WARNING type of optional environment variable makes the most sense for us.

We could set this new environment variable to "true" for all MFEs via @edx/frontend-build's setupTest.js file.

I think we have two options here:

  • Make that environment variable upstream and upgrade. This option has my two cents given it seems other consumers of the PubSub library also want to make that console.warn optional and that the maintainer seems willing to accept a contribution for this.
  • Patch pubsub-js using the approach in patch-package to remove the console.warn from pubsub-js altogether for our MFEs. Doing so would mean we don't need to wait on an upstream contribution but it does mean we'd be taking on the responsibility of maintaining a (albeit) small patch that might need to be re-implemented when pubsub-js is upgraded.

@arbrandes
Copy link

Thanks for taking the time to engage with upstream, @adamstankiewicz! I very much prefer the upstream contribution approach, but I'm not sure @ishahroz would be available to take on the work (includes the back-and-forth until it is merged, etc).

If not, we could leave an issue for the upstreaming open for somebody in our community to take on, and go the patch-package route for a short-term, temporary fix.

@adamstankiewicz adamstankiewicz moved this from Blocked to In review in Frontend Working Group Jan 24, 2023
@adamstankiewicz
Copy link
Member Author

adamstankiewicz commented Jan 24, 2023

FWIW, I opened a PR with the environment variable fix upstream here. I'll take on any back-and-forth until it gets merged.

The next steps here would be to:

  • Upgrade @edx/frontend-platform to use the new/latest version of pubsub-js with the environment variable fix
  • Set process.env.PUBSUBJS_DISABLE_EXISTING_VERSION_WARNING = true in @edx/frontend-build's setupTest.js file.

@arbrandes
Copy link

Upstream's been silent on the PR. Pinged them.

@arbrandes arbrandes moved this from In review to Blocked in Frontend Working Group May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Blocked
Development

No branches or pull requests

4 participants