Skip to content

feat: Add slot for whole application #1799

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xitij2000
Copy link
Contributor

Description

Adds a slot wrapping the entire application.

While the first two slots have pretty obvious use-cases the third has a use-case that propped up while trying to implement a way to have one plugin slot react to another. For instance, to inject a button in one slot that causes an action in another slot.

If developing code in the main application this would be through some type of shared state, for instance, using redux, or a context manager. Using redux from a plugin is a complex task and would require injecting a slice somehow, which doesn't fit in with the PluginSlot mechanism.

What we can do with a correctly-placed plugin-slot though, is to wrap in the entire app inside a context manager that can carry context for the plugin. That is the approach we've gone with here.

If this approach seems reasonable, it might make sense to have something similar for all MFEs.

An alternate approach is to use a package like: https://hookstate.js.org/docs/global-state/ (as recommended by @farhaanbukhsh) This would allow sharing state without needing to wrap the application; however, it introduces a new package as part of a plugin and that can introduce hard-to-resolve conflicts. If this approach is preferable, then it might make sense to have the package as part of the platform so conflicts can be avoided.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 9, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Apr 9, 2025

Thanks for the pull request, @xitij2000!

This repository is currently maintained by @openedx/2u-tnl.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks
Copy link

Thanks for the pull request, @xitij2000!

This repository is currently maintained by @openedx/2u-tnl.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link

codecov bot commented Apr 11, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 93.53%. Comparing base (a43027b) to head (1eb47c7).

Files with missing lines Patch % Lines
src/plugin-slots/AuthoringAppSlot/index.tsx 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1799      +/-   ##
==========================================
- Coverage   93.54%   93.53%   -0.02%     
==========================================
  Files        1136     1137       +1     
  Lines       23205    23208       +3     
  Branches     5000     5000              
==========================================
  Hits        21708    21708              
- Misses       1421     1424       +3     
  Partials       76       76              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Adds a slot wrapping the entire application.
@farhaanbukhsh farhaanbukhsh force-pushed the kshitij/full-app-slot branch from cf570dc to 1eb47c7 Compare April 13, 2025 11:05
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Apr 14, 2025
@brian-smith-tcril
Copy link
Contributor

trying to implement a way to have one plugin slot react to another

Is it possible to implement this without wrapping the entire application in a PluginSlot by utilizing React Context in env.config.jsx?

@xitij2000
Copy link
Contributor Author

trying to implement a way to have one plugin slot react to another

Is it possible to implement this without wrapping the entire application in a PluginSlot by utilizing React Context in env.config.jsx?

The context provider still needs to wrap all the components that need to share data, and they could be placed anywhere, so it needs to be as high up in the chain as possible.

I also feel something like this could be implemented in frontend-platform instead so it's available to all MFEs. One way would be to just add the wrapper to frontend-platform, and another would be to add another plugin mechanism for plugins to provide additional context wrappers.

@xitij2000 xitij2000 marked this pull request as ready for review April 16, 2025 06:44
@brian-smith-tcril
Copy link
Contributor

Wrapping an entire application (either in an individual MFE or within frontend-platform) doesn't match up with the intended use of frontend-plugin-framework slots.

That being said, I understand the need for plugins to be able to share information.

One reasonable path forward would be to:

  • Update frontend-platform's AppProvider to include a React context provider for a "PluginContext"
  • Document how to use the PluginContext in FPF plugins with a draft ADR
    • This should include best practices for using context, such as namespacing context variables with their associated plugin to avoid naming conflicts

@farhaanbukhsh
Copy link
Member

Hello @brian-smith-tcril @xitij2000 do you think we can wrap this up before teak code freeze(April 24th)? cc: @crathbun428 @bmtcril

@xitij2000
Copy link
Contributor Author

@brian-smith-tcril

I think the PluginContext approach makes a lot of sense. The only downside I see is that it puts all plugins into a single context, meaning that any change of state by any plugin will re-render all plugins. Also, a single state means that plugins need to properly namespace their settings, and ideally this is something that the context API should promote.

The hookstate approach relies on an external package, but has fewer of these issues, so might be worth exploring as well.

@farhaanbukhsh For now would it make sense to move this to hookstate to avoid blocking on this? I can make a quick PR wth the change.

@farhaanbukhsh
Copy link
Member

@xitij2000 yup I think we should go with the hookstate solution to get this working and then we can have a ticket to add an ADR if we have the budget and time for it.

@xitij2000
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Status: Waiting on Author
Development

Successfully merging this pull request may close these issues.

4 participants