Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Don't re-init the stickerpicker unless something actually changes #2862

Merged
merged 5 commits into from
Apr 4, 2019

Conversation

turt2live
Copy link
Member

Fixes element-hq/element-web#9354

#2801 introduced a change which tried to make sure that when the widget URL was changed that the picker would be re-mounted, however it accidentally introduced a regression. While it effectively did the task it wanted to, it failed to keep the previously-mounted sticker picker alive. This is because the Stickerpicker component is remounted when opened, and the _updateWidget function is called. This results in this.state not having the "current" widget, meaning a URL change is always detected when the component is remounted (room changes, open sticker picker).

Instead of remounting always, we'll instead track which sticker picker widget is being used out of band. This therefore means that whenever the Stickerpicker component is mounted it doesn't create a whole new widget, and the existing (background) picker can be used. This also fixes the loading screen that people would see when opening the sticker picker after switching rooms, something which the persistent widget stuff is supposed to solve.


This is done with a community hat on:

Signed-off-by: Travis Ralston <travis@t2bot,io>

Fixes element-hq/element-web#9354

#2801 introduced a change which tried to make sure that when the widget URL was changed that the picker would be re-mounted, however it accidentally introduced a regression. While it effectively did the task it wanted to, it failed to keep the previously-mounted sticker picker alive. This is because the Stickerpicker component is remounted when opened, and the _updateWidget function is called. This results in this.state not having the "current" widget, meaning a URL change is always detected when the component is remounted (room changes, open sticker picker). 

Instead of remounting always, we'll instead track which sticker picker widget is being used out of band. This therefore means that whenever the Stickerpicker component is mounted it doesn't create a whole new widget, and the existing (background) picker can be used. This also fixes the loading screen that people would see when opening the sticker picker after switching rooms, something which the persistent widget stuff is supposed to solve.
When setting, delete the old one. Because delete checks if it exists first, we can safely call this.

The change in FromWidgetPostMessageApi is just something noticed while debugging.
@turt2live turt2live requested a review from a team April 2, 2019 01:50
@turt2live
Copy link
Member Author

For additional context: the reason why multiple stickers were being issued was because the Stickerpicker wasn't being torn down fully, meaning the onAction handler was still present. This would lead to multiple handlers dealing with the single dispatch, ergo sending multiple stickers.

@jryans jryans self-requested a review April 2, 2019 08:41
@turt2live turt2live requested a review from jryans April 3, 2019 23:17
Copy link
Collaborator

@jryans jryans left a comment

Choose a reason for hiding this comment

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

Great, thanks for working on this! 😁

src/stores/ActiveWidgetStore.js Outdated Show resolved Hide resolved
@turt2live turt2live merged commit a61ab4e into develop Apr 4, 2019
@turt2live turt2live deleted the travis/stickerpicker/remount branch April 4, 2019 15:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sticker picker sends a sticker multiple times after switching rooms
2 participants