Repository navigation
[MM-70322] Prevent duplicate GitHub sidebar components when the plugin is re-initialized - #1084
Open
cursor[bot] wants to merge 3 commits into
Open
cursor[bot] wants to merge 3 commits into
cursor[bot] wants to merge 3 commits into
Conversation
…tializes the plugin Track the components registered during initialize and unregister them in uninitialize, which the webapp calls on plugin upgrade and removal (the deprecated deinitialize is skipped on upgrade). Skip registration when an in-flight initialize has been superseded while awaiting getConnected. Co-authored-by: mattermost-code <matty-code@mattermost.com>
Co-authored-by: mattermost-code <matty-code@mattermost.com>
Co-authored-by: mattermost-code <matty-code@mattermost.com>
Contributor
|
@marianunez - checking in - we've reached the required number of approvals here - if this is good to merge, please click the button! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On upgrade, the webapp clears the plugin's components and loads the new bundle. But
initializeawaitsgetConnectedbefore registering anything. Aninitializethat is still waiting on that request when the next bundle loads (overlapping upgrade events on a slow connection) resumes and registers its components on top of the new ones. That is how the duplicate GitHub buttons end up in the team sidebar. The plugin also implemented only the deprecateddeinitialize, which the webapp skips when one bundle replaces another (it callsuninitializethere), so nothing cleaned up.Changes in
webapp/src/index.js:initialize, and unregister them all in a newuninitialize. This replacesdeinitializeand still removes the click listener.initializealso calls it first, so re-initializing replaces components instead of adding more.initializethat was uninitialized or superseded whilegetConnectedwas in flight returns before registering anything.Websocket handlers and the reconnect handler are keyed by plugin ID, so they can't duplicate; they are unchanged.
Servers from 12.0 on also drop registrations from a replaced bundle script, so this mostly shows up on older servers like the one in the report. The plugin-side guard covers both.
Testing
webapp/src/index.test.jscover unregistering onuninitialize, skipping registration when uninitialized or re-initialized mid-connect, and replacing components on re-initialize. All four fail against the old code.connect,sidebarandsmokespecs pass (11 tests).npm run lint,npm run check-typesand the full jest suite (37 tests) pass.Ticket Link
https://mattermost.atlassian.net/browse/MM-70322
Change Impact: Medium 🟡
Changes Breakdown:
+32 -12 Production Changes (24.9%)
+133 -0 Test Changes (75.1%)
Regression Risk: The change alters the plugin lifecycle contract by renaming
deinitializetouninitialize, so cleanup may not run on hosts that still call onlydeinitialize. The change is limited towebapp/src/index.js, and the new tests cover uninitialize during a pendinggetConnected, overlapping initialization, and reinitialization.Generated by CodeRabbitAI