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): reinit behavior on presentation change #24828

Merged
merged 27 commits into from
Mar 11, 2022
Merged

Conversation

averyjohnston
Copy link
Contributor

@averyjohnston averyjohnston commented Feb 21, 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 the presentation prop on datetime is changed programmatically, behaviors such as the intersection observers and keyboard listeners are disconnected.

Issue URL: Resolves #24826

What is the new behavior?

  • Behavior is re-inited when the presentation prop is changed.
  • Several calendarBodyRef uses were updated to avoid being set to null due to a Stencil bug.

Does this introduce a breaking change?

  • Yes
  • No

Other information

@averyjohnston averyjohnston requested a review from a team as a code owner February 21, 2022 20:08
@github-actions github-actions bot added the package: core @ionic/core package label Feb 21, 2022
core/src/components/datetime/datetime.tsx Outdated Show resolved Hide resolved
@liamdebeasi liamdebeasi self-requested a review February 22, 2022 14:01
core/src/components/datetime/datetime.tsx Outdated Show resolved Hide resolved
core/src/components/datetime/datetime.tsx Outdated Show resolved Hide resolved
core/src/components/datetime/datetime.tsx Outdated Show resolved Hide resolved
core/src/components/datetime/datetime.tsx Outdated Show resolved Hide resolved
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.

Also, can we add E2E tests to verify this new behavior?

@averyjohnston averyjohnston removed the request for review from liamdebeasi February 23, 2022 21:54
core/src/components/datetime/datetime.tsx Outdated Show resolved Hide resolved
core/src/components/datetime/datetime.tsx Outdated Show resolved Hide resolved
@liamdebeasi
Copy link
Contributor

I am noticing the following error getting thrown during the E2E tests:

TypeError: Cannot read properties of undefined (reading 'initializeCalendarIOListeners')
    at initializeListeners (ion-datetime.entry.js:1659)
    at Datetime.componentDidRender (ion-datetime.entry.js:1749)
    at safeCall (index-765cc965.js:1580)
    at postUpdateComponent (index-765cc965.js:1481)
    at postUpdate (index-765cc965.js:1416) undefined

Perhaps this is why the test is failing?

@averyjohnston
Copy link
Contributor Author

I'm still working on it; there are a few different issues that need addressing. I'll re-request review when it's ready again.

@github-actions github-actions bot added the package: vue @ionic/vue package label Mar 2, 2022
* purposes, e.g. to ensure month selection works.
* @internal
*/
@Event() ionWorkingPartsDidChange!: EventEmitter<DatetimeParts>;
Copy link
Contributor Author

@averyjohnston averyjohnston Mar 2, 2022

Choose a reason for hiding this comment

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

This should replace the InitMonthDidChangeEvent function completely. I'll make a separate PR to update the other tests once this has cleared review.

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 a way we can have a check that is only done in tests? My concern with this is that this extra code is only needed for tests but is now going to run in every production Ionic app that uses ion-datetime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't able to find one, but I'm open to ideas. The old util (InitMonthDidChangeEvent) fits the bill and uses a mutation observer to indirectly watch for the month to change, but it doesn't account for the month element being re-rendered (and thus the reference to the observed element being lost) when presentation is changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Spent some time exploring an alternative way to test this behavior. Here's a branch that shows how we can drop the internal event from ion-datetime: https://github.com/ionic-team/ionic-framework/tree/test/FW-844.

It will apply a mutation observer to dispatch a custom event once the calendar body is manipulated. It will also re-attach the observer to the correct element node after the presentation is changed.

If you like this approach, feel free to take any parts of it/merge it into your working branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sean-perkins Thanks for that! I cleaned it up and brought it in 👍 cc @liamdebeasi

@averyjohnston
Copy link
Contributor Author

Alright, should finally be good to go now! Whew.

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.

Good to go other than my one comment

packages/vue/src/proxies.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the package: vue @ionic/vue package label Mar 11, 2022
Copy link
Contributor

@sean-perkins sean-perkins left a comment

Choose a reason for hiding this comment

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

🎉

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.

bug: datetime intersection observers get disconnected when changing presentation programmatically
3 participants