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(OverlayToaster): Fix toasts being cut off if show() called too quickly #7049

Merged
merged 4 commits into from
Nov 7, 2024

Conversation

jscheiny
Copy link
Contributor

@jscheiny jscheiny commented Nov 7, 2024

Fixes #7034

Checklist

  • Includes tests
  • Update documentation (N/A)

Changes proposed in this pull request:

This issue appears to be a react css transition group issue, but we can mitigate it on our side by effectively debouncing the show() call. Now when a user calls show() if there's been a toasted shown in the last 50ms, the new toast will be added to a queue and only shown after that time has elapsed. Any other show() calls that happen within that window will also be added to the queue and only one new toast will be shown after each 50ms increment.

Screenshots

Without this change we get this ugly behavior:
Screenshot 2024-11-07 at 1 29 05 PM

With the change it animates in properly:
Screenshot 2024-11-07 at 1 29 16 PM

@changelog-app
Copy link

changelog-app bot commented Nov 7, 2024

Generate changelog in packages/core/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

fix(OverlayToaster): Fix toasts being cut off if show() called too quickly

Check the box to generate changelog(s)

  • Generate changelog entry

@jscheiny jscheiny marked this pull request as ready for review November 7, 2024 18:33
@svc-palantir-github
Copy link

Fix comment

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

toasts: ToastOptions[];
}

const QUEUE_TIMEOUT_MS = 50;
Copy link
Contributor

Choose a reason for hiding this comment

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

What determines that the timeout should be 50ms? Is this something that we should potentially make configurable?

Copy link
Contributor Author

@jscheiny jscheiny Nov 7, 2024

Choose a reason for hiding this comment

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

This was based on experimentation on my part, it was a value that seemed to never exhibit issues with this problem (+ some buffer to be safe) and not have too much apparent effect on the UX of the component. I don't see a particular reason right now to make this configurable.

toaster.show({ message: "one" });
toaster.show({ message: "two" });
toaster.show({ message: "six" });
await delay(150);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way we can tie these hardcoded values to the value of QUEUE_TIMEOUT_MS? That might make them a bit less ambiguous in the context of these tests. Perhaps we could leave a comment or even export reference the constant itself in code:

await delay(3 * QUEUE_TIMEOUT_MS);

Also, should we be using timer mocks in our tests?

Copy link
Contributor Author

@jscheiny jscheiny Nov 7, 2024

Choose a reason for hiding this comment

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

Yeah good call on the delay, will export that. I attempted to user the timer mocks and I wasn't able to get them to work, will give them another shot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Figured out what I messed up and switched to fake timers 👍

}

private handleQueueTimeout = () => {
const nextToast = this.queue.toasts.shift();
this.queue.isRunning = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to set isRunning to false during each execution of the timeout? Would it make sense to check that the queue is empty first? Something like:

if (this.queue.toasts.length === 0) {
    this.queue.isRunning = false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good call. I ended up implementing this slightly differently but with the same intent.

@svc-palantir-github
Copy link

CR

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@jscheiny jscheiny merged commit 08c0376 into develop Nov 7, 2024
13 checks passed
@jscheiny jscheiny deleted the js/fix-toaster-cut-off branch November 7, 2024 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Showing multiple toasts in quick succession flows over top of screen
4 participants