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

Adding multiple plugins with wrapComponents on the same core component seems broken #7232

Closed
DayS opened this issue May 1, 2021 · 6 comments · May be fixed by codingfragments/tvh-guide#134

Comments

@DayS
Copy link
Contributor

DayS commented May 1, 2021

Q&A (please complete the following information)

  • OS: macOS
  • Browser: Chrome
  • Version: 90.0.4430.93
  • Method of installation: npm
  • Swagger-UI version: [e.g. 3.47.1]
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Swagger/OpenAPI definition is not relevant for this issue bug here is a sample:

openapi: "3.0.1"
paths:
  /my-endpoint:
    get:
      operationId: getMyAwesomeEndpoint
      responses:
        "200":
          description: "Successful operation"

Swagger-UI configuration options:

import SwaggerUI from 'swagger-ui'
SwaggerUI({
  spec: spec,
  deepLinking: true,
  dom_id: '#swagger',
  plugins: [
    {
      wrapComponents: {
        info: (Original, { React, getComponents }) => (props) => {
          return React.createElement("div", null, [
            React.createElement("h3", {key: 1}, "Hello world! I am above the Info component"),
            React.createElement(Original, Object.assign({key: 2}, props)),
          ])
        }
      }
    },
    {
      wrapComponents: {
        info: (Original, { React, getConfig }) => (props) => {
          return React.createElement("div", null, [
            React.createElement(Original, Object.assign({key: 2}, props)),
            React.createElement("h4", {key: 1}, "Hello world! I am below the Info component") ,
          ])
        }
      }
    }
  ]
});

Describe the bug you're encountering

When multiple plugins are configured with wrapComponents entry on the same core component (info for example), only the last one is applied.
I was expected all of them to be applied in a chain pattern. They should end up being embedded according to where the Original component is applied.
So, in this example I should see both my titles before and after the info content.

Fix

I pinpointed the issue on system.js where plugins are combined.
As systemExtend() is called with an empty object for dest, we can't retrieve the existing components.

I was able to fix this issue by replacing .reduce(systemExtend, {}) with .reduce(systemExtend, toolbox.getComponents()) on system.js

WDYT ?

@mathis-m
Copy link
Contributor

mathis-m commented May 1, 2021

@tim-lai as already reported for wrapSelectors in #7157 we should think of a general refactor of the system.js where the wrapping is done in appropriate way.

@DayS
Copy link
Contributor Author

DayS commented May 1, 2021

I agree :)

In the meantime, can we expect a small fix on this point and the one in the related issue or is it out of scope for now ?

@tim-lai
Copy link
Contributor

tim-lai commented May 18, 2021

@DayS I added some comments to your PR #7236. Pending some tweaks, this specific issue can get fixed. I do agree that it is safer to add a config option to change the current default behavior.

@mathis-m fyi, I did a quick experiment with both this issue and #7157. The PR associated with this ticket does not address the wrapSelectors referenced in #7157

@tim-lai
Copy link
Contributor

tim-lai commented Jun 10, 2021

fixed via #7236

@tim-lai tim-lai closed this as completed Jun 10, 2021
@char0n
Copy link
Member

char0n commented May 7, 2024

Hi everybody,

The expected behavior described in this issue has always been intended. It shouldn't matter if whether the plugins have been registered via presets or passed by the plugins option. Having said that, this is just a bug in the original behavior, and the expected behavior (called chaining in this issue) should be the default one. Wrapping actions and selectors already works like that (ref #7304).

In #7236, the remediation was provided, but unfortunately it also contains hidden bug, where the original components objects is being mutated by the combined plugins because of this line:

 const dest = pluginOptions.pluginLoadType === "chain" ? toolbox.getComponents() : {}

Action: we're gonna revert 516e666 and replace it with non-configurable solution. We're going to fix the mutation bug introduced by the line above.

@char0n
Copy link
Member

char0n commented May 7, 2024

Addressed in #9919

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

Successfully merging a pull request may close this issue.

4 participants