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

[core] fix: get toasters timeout Infinity to match behavior of timeout 0 #7059

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

JML321
Copy link

@JML321 JML321 commented Nov 12, 2024

Fixes #6742

A toast with timeout: Infinity closes immediately.

See this sandbox https://codesandbox.io/p/sandbox/blueprint-toast-issue-forked-4t9r9t?file=%2Fsrc%2FApp.js%3A17%2C4.

However, a Toast with timeout: Infinity should disable the timeout, just like a Toast with timeout: 0.

Additionally, a test case for timeout: Infinity is needed.

The Issue

The error is in blueprint/packages/core/src/components/toast/toast2.tsx, specifically the line:

isTimeoutEnabled = timeout != null && timeout > 0;

Currently, when timeout = Infinity, then isTimeoutEnabled = True. When Infinity is passed as the timeout, due to useTimeout's functionality, the toast closes immediately with a 0 second delay.

This code needs to be fixed so when timeout = Infinity, then isTimeoutEnabled = False (i.e. the timeout is disabled).

Changes proposed in this pull request:

Three changes:

  1. Adding an extra line as a comment to share where I found that "timeout: Infinity" should disable the timeout.
  2. Fix isTimeoutEnabled so that for timeout = Infinity, isTimeoutEnabled is False, not True. In addition, the isTimeoutEnabled value is preserved for all other inputs of timeout.
  3. Creating a test case that sees whether a toaster with timeout: Infinity has received a dismiss, returning a False if it has.

These changes produced correct functionality on my local computer.

Tests

  • Passes tests for packages\core

Reviewers should focus on:

  1. If the added comment line should be modified or deleted
  2. If the new isTimeoutEnabled matches the wanted functionality, such that isTImeoutEnabled is True when the timeout is greater than 0, and False when the timeout is either null, less than or equal to 0, and Infinity.
  3. Whether the test case achieves what was requested for in the open issue.

Screenshots

image
image

@changelog-app
Copy link

changelog-app bot commented Nov 12, 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

[core] fix: get toasters timeout Infinity to match behavior of timeout 0

Check the box to generate changelog(s)

  • Generate changelog entry

Copy link
Contributor

@jscheiny jscheiny left a comment

Choose a reason for hiding this comment

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

Thanks for making this change and adding tests. Just a few minor comments

@@ -44,7 +44,8 @@ export const Toast2 = React.forwardRef<HTMLDivElement, ToastProps>((props, ref)
const clearTimeout = React.useCallback(() => setIsTimeoutStarted(false), []);

// Per docs: "Providing a value less than or equal to 0 will disable the timeout (this is discouraged)."
const isTimeoutEnabled = timeout != null && timeout > 0;
// Per github, issue 6742: "timeout: Infinity should also behave the same as timeout: 0"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove both these comments, they don't add anything that the code does not provide here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, lets update the docs for the timeout prop to mention the behavior of Infinity.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I've removed the comments and updated the timeout prop documentation to include the Infinity behavior. Let me know if you'd like me to make any other changes.

Copy link
Contributor

@jscheiny jscheiny left a comment

Choose a reason for hiding this comment

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

One minor docs change below, thanks for making this contribution

@@ -47,7 +47,7 @@ export interface ToastProps extends Props, IntentProps {

/**
* Milliseconds to wait before automatically dismissing toast.
* Providing a value less than or equal to 0 will disable the timeout (this is discouraged).
* Providing a value less than or equal to 0 or Infinity will disable the timeout (this is discouraged).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Providing a value less than or equal to 0 or Infinity will disable the timeout (this is discouraged).
* Setting this to Infinity or a value less than or equal to 0 will disable the timeout (this is discouraged).

Minor nit to make sure that this is clear that we're not referring to values less than infinity

Copy link
Author

Choose a reason for hiding this comment

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

Great! Glad to help.

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.

Toaster with timeout zero is dismissed early
2 participants