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: non-reference clone of transferred listeners #1080

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

mshanemc
Copy link
Contributor

@mshanemc mshanemc commented Jun 7, 2024

What does this PR do?

scenario:

  1. you build a plugin with an "early" hook (think init or prerun) which instantiates lifecycle and subscribes a listener with an uniqueId.
  2. your plugin uses an older version of this library than the CLI it's installed into
  3. when the "main" CLI loads Lifecycle, it tries to transfer the listeners.
  4. the map of unique listeners is passed in to the new Lifecycle and deleted from the old one
  5. because it was passed by ref, the delete of listeners from the old Lifecycle also deletes them from the new one
  6. non-unique listeners were protected from ref-mutation bug by the spread operator (see existing code comment)

This PR adds a cloning step for the map of unique listeners and some UT to verify ref-breaking

the native structuredClone can't be used because the callback value in the maps is a function and can't be cloneable.

What issues does this PR fix or reference?

[skip-validate-pr]

@mshanemc mshanemc requested a review from a team as a code owner June 7, 2024 14:51
Copy link

git2gus bot commented Jun 7, 2024

This issue has been linked to a new work item: W-15959518

@mshanemc mshanemc changed the title fix: structured clone of transferred listeners fix: non-reference clone of transferred listeners Jun 7, 2024
@cristiand391 cristiand391 merged commit f5b2b02 into main Jun 7, 2024
76 checks passed
@cristiand391 cristiand391 deleted the sm/fragile-lifecycle-listeners branch June 7, 2024 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants