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(datetime): handle invalid dates when value changes #25049

Merged
merged 9 commits into from
Apr 5, 2022

Conversation

sean-perkins
Copy link
Contributor

@sean-perkins sean-perkins commented Apr 4, 2022

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

When assigning an invalid value to a datetime in Firefox, such as:

document.querySelector('ion-datetime[presentation="time"]').value = '4:10'; // Valid value would be 04:10

In Firefox an exception will be thrown that states:

TypeError: parseDate(...) is undefined

This exception is not present in Safari or Chrome and isn't helpful or clear to developers.

What is the new behavior?

  • Adds check for a valid parsable date before trying to assign active parts
  • No exception is thrown in Firefox
  • Warning is logged to the developer that an invalid date string was provided

Does this introduce a breaking change?

  • Yes
  • No

Other information

@sean-perkins sean-perkins requested a review from a team as a code owner April 4, 2022 03:01
@github-actions github-actions bot added the package: core @ionic/core package label Apr 4, 2022
Copy link
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

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

Looks good other than the comment. Don't forget to update the commit subject to be more descriptive. Maybe something like "warn when parsing an invalid date value"?

@@ -106,6 +106,8 @@ export const test = base.extend<CustomFixtures>({
page.setIonViewport = async () => {
const currentViewport = page.viewportSize();

await page.waitForSelector('ion-content');
Copy link
Contributor

Choose a reason for hiding this comment

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

With the other fix I merged into main, is this still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The behavior it was added to resolve, was fixed by your other changes. There is some value of it existing, in that we shouldn't be calling setIonViewport on a test template that doesn't use ion-content. If we use the waitForSelector, an invalid test will fail and help inform that that tag is expected in the test file. I think this is rare though, so I'd be happy to remove for now and re-add if we would find value in the safe guard.

@sean-perkins sean-perkins merged commit 982dc85 into main Apr 5, 2022
@sean-perkins sean-perkins deleted the fix/datetime-firefox branch April 5, 2022 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants