fix(modal): fix timeout edge cases with custom_id
reuse and long-running callbacks
#914
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
This PR fixes two edge cases with
ui.Modal
timeouts (send_modal(title, id, components)
isn't affected, to be clear).1.
Since modals are keyed by
(user_id, custom_id)
, sending two modals with the samecustom_id
to the same user (e.g. when they run the command on two devices, or close + rerun) could result in a situation where the timeout of the first modal removes the second modal from the store.example
Let's assume a command
/test
exists, which responds with a modal with a 30 second timeout, and a fixedcustom_id
:/test
on device A, and does not submit the modal/test
on device BThis PR fixes that by canceling the timeout of the first modal before adding the second one to the store.
Ideally, custom IDs should always be unique when used with
ui.Modal
, but the examples were doing exactly the opposite. I've updated those and added a documentation note.2.
Previously, the modal timeout would (indirectly) be stopped after the
callback
ran.If there's a long-running callback however, the timeout could fire while the callback was still running, which is both incorrect and resulted in an exception when the dispatch function would try to remove the modal after the callback did finish.
example
Again, let's assume there's a modal with a 30 second timeout:
on_timeout
remove_modal
call failsThis PR fixes that by cancelling the timeout before executing the callback (and later possibly reinstating it if the modal interaction wasn't responded to).
I believe this is also what could've happened here, but it's difficult to say for sure.
Checklist
task lint
task pyright