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

Fix interoperability issue regarding Event properties #36386

Merged
merged 2 commits into from
Jun 30, 2022

Conversation

alecpl
Copy link
Contributor

@alecpl alecpl commented May 17, 2022

  • make possible to re-set read-only event properties
  • use hydrateObj() to set delegateTarget property

Fixes #36207

@GeoSot
Copy link
Member

GeoSot commented May 17, 2022

Thank you, @alecpl, for your PR.

Please take under consideration the need of below change (not sure if is needed), and it would be great to support your Pr with the proper tests

function hydrateObj(obj, meta) {
  for (const [key, value] of Object.entries(meta || {})) {
    try {
      obj[key] = value
    } catch {
      Object.defineProperty(obj, key, {
       configurable: true,
        get() {
          return value
        }
      })
    }
  }

  return obj
}

@alecpl
Copy link
Contributor Author

alecpl commented May 18, 2022

@GeoSot I considered the change before, but I'm not sure it's really worth it. As for the tests, I'm afraid I will not be able to do that, as I have no idea about bootstrap's tests nor build system.

@GeoSot
Copy link
Member

GeoSot commented May 19, 2022

I can help you witting the tests, but at least need a codepen that replicates the issue, you are trying to solve here

@alecpl
Copy link
Contributor Author

alecpl commented May 20, 2022

The main issue is if you have an external library like cash-dom that is handling the same event as Bootstrap (e.g. a click handler on a Tab) and is setting the delegateTarget (in this case, but I can imagine other properties with the same issue). Cash-dom makes the delegateTarget property read-only and Bootstrap can't just do event.delegateTarget = something assignment.

The second part of the patch (configurable: true) makes sure that read-only properties set by Bootstrap can be re-set outside.

Now thinking about this, and considering https://github.com/jquery/jquery/blob/5d5ea015114092c157311c4948f7cc3d8c8e7f8a/src/event.js#L306 we might indeed need the change you suggested. I mean it would be nice to be consistent inside Bootstrap and make all event properties read-only, but it may break compatibility with jQuery. I didn't test that.

@GeoSot
Copy link
Member

GeoSot commented Jun 11, 2022

I did the change and added some tests to help. Just to note down here, I am not sure if I have understood the real issue on this situation, and if the proposed solution is valid. So if any other js dev have better knowledge, please d not hesitate to write an opinion

@julien-deramond julien-deramond self-requested a review June 28, 2022 08:36
@GeoSot GeoSot force-pushed the dev/delegate-target-fix branch 2 times, most recently from 987b889 to e7707ce Compare June 30, 2022 18:01
alecpl and others added 2 commits June 30, 2022 22:32
- make possible to re-set read-only event properties
- use hydrateObj() to set delegateTarget property

Fixes twbs#36207
@GeoSot
Copy link
Member

GeoSot commented Jun 30, 2022

@julien-deramond are we going to merge it?

@GeoSot GeoSot merged commit 505e023 into twbs:main Jun 30, 2022
@GeoSot GeoSot mentioned this pull request Jul 18, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

TypeError: setting getter-only property "delegateTarget"
3 participants