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

OCPBUGS-36678: Add useQuickStartContext hook and expose it via dynamic plugin API #14055

Merged

Conversation

vojtechszocs
Copy link
Contributor

@vojtechszocs vojtechszocs commented Jul 12, 2024

Problem

When working with React contexts in Console frontend and its dynamic plugins, the context object passed to React.useContext hook must be identical (i.e. === referentially equal) in order for the context value (hook result) to work properly across all plugins.

The exact use case here is importing QuickStartContext from @patternfly/quickstarts package.

From a plugin's perspective, unless @patternfly/quickstarts is marked as a shared module, that plugin will always use its own "copy" of @patternfly/quickstarts module(s) during its webpack build. This behavior is normal and expected; code not shared between the host application and its plugins can be loaded multiple times in possibly different versions.

The problem arises when some objects, like QuickStartContext mentioned above, must be referentially equal in order for plugin to properly interoperate with the host application.

❗ If a plugin uses @openshift-console/dynamic-plugin-sdk-webpack version that includes #13992 and that plugin also uses PatternFly 5 or higher, @patternfly/quickstarts will not be treated as a shared module. This is because Console provided PatternFly shared modules are limited to PF 4 implementation for backwards compatibility reasons. Plugins using PatternFly 5 or higher will share PF modules between themselves via dynamic modules #13521.

Solution

Add new React hook useQuickStartContext and expose it via @openshift-console/dynamic-plugin-sdk package.

// Plugin code, before:
import { QuickStartContext, QuickStartContextValues } from '@patternfly/quickstarts';
// ..
const { setActiveQuickStart } = useContext<QuickStartContextValues>(QuickStartContext);

// Plugin code, updated (*):
import { useQuickStartContext } from '@openshift-console/dynamic-plugin-sdk';
// ..
const { setActiveQuickStart } = useQuickStartContext();

(*) Requires that we publish a new version of @openshift-console/dynamic-plugin-sdk package with this change included.

Notes

Console already has withQuickStartContext React utility that injects quickStartContext prop into the wrapped component. The value of quickStartContext prop is the context value retrieved via React.useContext(QuickStartContext) which means the prop name is misleading and we should improve it at some point.

@rhamilto @TheRealJon The above mentioned withQuickStartContext utility seems to be unused in Console frontend and not exposed via dynamic plugin API. I'd suggest removing it, do you have any thoughts or objections?

@openshift-ci openshift-ci bot added component/core Related to console core functionality component/knative Related to knative-plugin approved Indicates a PR has been approved by an approver from all required OWNERS files. component/pipelines Related to pipelines-plugin component/sdk Related to console-plugin-sdk component/shared Related to console-shared component/topology Related to topology labels Jul 12, 2024
@vojtechszocs vojtechszocs changed the title Add useQuickStartContext hook and expose it via dynamic plugin API OCPBUGS-36678: Add useQuickStartContext hook and expose it via dynamic plugin API Jul 12, 2024
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 12, 2024
@openshift-ci-robot
Copy link
Contributor

@vojtechszocs: This pull request references Jira Issue OCPBUGS-36678, which is invalid:

  • expected the bug to target the "4.17.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

Problem

When working with React contexts in Console frontend and its dynamic plugins, the context object passed to React.useContext hook must be identical (i.e. === referentially equal) in order for the context value (hook result) to work properly across all plugins.

The exact use case here is importing QuickStartContext from @patternfly/quickstarts package.

From a plugin's perspective, unless @patternfly/quickstarts is marked as a shared module, that plugin will always use its own "copy" of @patternfly/quickstarts module(s) during its webpack build. This behavior is normal and expected; code not shared between the host application and its plugins can be loaded multiple times in possibly different versions.

The problem arises when some objects, like QuickStartContext mentioned above, must be referentially equal in order for plugin to properly interoperate with the host application.

❗ If a plugin uses @openshift-console/dynamic-plugin-sdk-webpack version that includes #13992 and that plugin also uses PatternFly 5 or higher, @patternfly/quickstarts will not be treated as a shared module. This is because Console provided PatternFly shared modules are limited to PF 4 implementation for backwards compatibility reasons. Plugins using PatternFly 5 or higher will share PF modules between themselves via dynamic modules #13521.

Solution

Add new React hook useQuickStartContext and expose it via @openshift-console/dynamic-plugin-sdk package.

// Plugin code, before:
import { QuickStartContext, QuickStartContextValues } from '@patternfly/quickstarts';
// ..
const { setActiveQuickStart } = useContext<QuickStartContextValues>(QuickStartContext);

// Plugin code, updated (*):
import { useQuickStartContext } from '@openshift-console/dynamic-plugin-sdk';
// ..
const { setActiveQuickStart } = useQuickStartContext();

(*) Requires that we publish a new version of @openshift-console/dynamic-plugin-sdk package with this change included.

Notes

Console already has withQuickStartContext React utility that injects quickStartContext prop into the wrapped component. The value of quickStartContext prop is the context value retrieved via React.useContext(QuickStartContext) which means the prop name is misleading and we should improve it at some point.

@rhamilto @TheRealJon The above mentioned withQuickStartContext utility seems to be unused in Console frontend and not exposed via dynamic plugin API. I'd suggest removing it, do you have any thoughts or objections?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. label Jul 12, 2024
@rhamilto
Copy link
Member

@rhamilto @TheRealJon The above mentioned withQuickStartContext utility seems to be unused in Console frontend and not exposed via dynamic plugin API. I'd suggest removing it, do you have any thoughts or objections?

No objections if it unused, but we probably need to deprecate first.

@jhadvig
Copy link
Member

jhadvig commented Jul 15, 2024

/jira refresh

@openshift-ci-robot openshift-ci-robot added the jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. label Jul 15, 2024
@openshift-ci-robot
Copy link
Contributor

@jhadvig: This pull request references Jira Issue OCPBUGS-36678, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.17.0) matches configured target version for branch (4.17.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @yapei

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot removed the jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. label Jul 15, 2024
@openshift-ci openshift-ci bot requested a review from yapei July 15, 2024 14:45
Copy link
Member

@rhamilto rhamilto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2024
@vojtechszocs
Copy link
Contributor Author

Forgot to add API docs change, I'll update the PR.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2024
@rhamilto
Copy link
Member

/lgtm
/label tide/merge-method-squash

@openshift-ci openshift-ci bot added tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. lgtm Indicates that a PR is ready to be merged. labels Jul 15, 2024
Copy link
Contributor

openshift-ci bot commented Jul 15, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhamilto, vojtechszocs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vojtechszocs
Copy link
Contributor Author

/retest

@rhamilto
Copy link
Member

/label acknowledge-critical-fixes-only

@openshift-ci openshift-ci bot added the acknowledge-critical-fixes-only Indicates if the issuer of the label is OK with the policy. label Jul 15, 2024
Copy link
Contributor

openshift-ci bot commented Jul 15, 2024

@vojtechszocs: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot bot merged commit 7ba2bdc into openshift:master Jul 15, 2024
6 checks passed
@openshift-ci-robot
Copy link
Contributor

@vojtechszocs: Jira Issue OCPBUGS-36678: All pull requests linked via external trackers have merged:

Jira Issue OCPBUGS-36678 has been moved to the MODIFIED state.

In response to this:

Problem

When working with React contexts in Console frontend and its dynamic plugins, the context object passed to React.useContext hook must be identical (i.e. === referentially equal) in order for the context value (hook result) to work properly across all plugins.

The exact use case here is importing QuickStartContext from @patternfly/quickstarts package.

From a plugin's perspective, unless @patternfly/quickstarts is marked as a shared module, that plugin will always use its own "copy" of @patternfly/quickstarts module(s) during its webpack build. This behavior is normal and expected; code not shared between the host application and its plugins can be loaded multiple times in possibly different versions.

The problem arises when some objects, like QuickStartContext mentioned above, must be referentially equal in order for plugin to properly interoperate with the host application.

❗ If a plugin uses @openshift-console/dynamic-plugin-sdk-webpack version that includes #13992 and that plugin also uses PatternFly 5 or higher, @patternfly/quickstarts will not be treated as a shared module. This is because Console provided PatternFly shared modules are limited to PF 4 implementation for backwards compatibility reasons. Plugins using PatternFly 5 or higher will share PF modules between themselves via dynamic modules #13521.

Solution

Add new React hook useQuickStartContext and expose it via @openshift-console/dynamic-plugin-sdk package.

// Plugin code, before:
import { QuickStartContext, QuickStartContextValues } from '@patternfly/quickstarts';
// ..
const { setActiveQuickStart } = useContext<QuickStartContextValues>(QuickStartContext);

// Plugin code, updated (*):
import { useQuickStartContext } from '@openshift-console/dynamic-plugin-sdk';
// ..
const { setActiveQuickStart } = useQuickStartContext();

(*) Requires that we publish a new version of @openshift-console/dynamic-plugin-sdk package with this change included.

Notes

Console already has withQuickStartContext React utility that injects quickStartContext prop into the wrapped component. The value of quickStartContext prop is the context value retrieved via React.useContext(QuickStartContext) which means the prop name is misleading and we should improve it at some point.

@rhamilto @TheRealJon The above mentioned withQuickStartContext utility seems to be unused in Console frontend and not exposed via dynamic plugin API. I'd suggest removing it, do you have any thoughts or objections?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-bot
Copy link
Contributor

[ART PR BUILD NOTIFIER]

This PR has been included in build openshift-enterprise-console-container-v4.17.0-202407160240.p0.g7ba2bdc.assembly.stream.el9 for distgit openshift-enterprise-console.
All builds following this will include this PR.

@vojtechszocs
Copy link
Contributor Author

/cherry-pick release-4.16

@openshift-cherrypick-robot

@vojtechszocs: new pull request created: #14070

In response to this:

/cherry-pick release-4.16

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledge-critical-fixes-only Indicates if the issuer of the label is OK with the policy. approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality component/knative Related to knative-plugin component/pipelines Related to pipelines-plugin component/sdk Related to console-plugin-sdk component/shared Related to console-shared component/topology Related to topology jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants