609 Commits

Author SHA1 Message Date
1ba9973857 fix(react): cleanup functions are execute for lifecycle hooks (#28319)
Issue number: Resolves #28186

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Ionic lifecycle hooks do not execute a cleanup function when the
underlying `useEffect` is unmounted.

```ts
useEffect(() => {
  return () => {
     console.log('cleanup'); // called
   };
});

useIonViewWillEnter(() => {
  return () => {
     console.log('cleanup'); // never called
  };
});
```

Ionic's implementation registers the lifecycle callback to be handled at
a later time, by the page managers. However, it does not keep a
reference to the returned callback, so it cannot execute it when the
`useEffect` is unmounted.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Ionic lifecycle hooks execute dev-specified cleanup functions

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev-build: `7.4.4-dev.11696956070.1faa3cfe`

This PR builds on the changes in #28316.

---------

Co-authored-by: Maria Hutt <maria@ionic.io>
Co-authored-by: Amanda Johnston <90629384+amandaejohnston@users.noreply.github.com>
2023-10-12 19:19:01 +00:00
f14a59c5e0 fix(react): lifecycle events are removed on page unmount (#28316)
Issue number: N/A

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

While debugging #28186, Maria and I identified that Ionic's lifecycle
event listeners (`ionViewWillEnter`, etc.) were being registered
multiple times on the same `.ion-page` element. This resulted in
problematic behavior, where a user's implementation of our lifecycle
hooks, would execute their callback multiple times.

```ts
useIonViewWillEnter(() => {
  // This is called 2x for every time the `ionViewWillEnter` event is emitted (in React 18, dev mode)
  console.log('hello world'); 
});
```

When the Ionic lifecycle event listeners are registered in React, we
bind the scope of the class to the callback function. When removing the
event listener we additional use the `.bind` syntax.

```tsx
componentDidMount() {
  element.addEventListener('ionViewWillEnter', this.ionViewWillEnter.bind(this));
} 

componentWillUnmount() {
  // This creates a new instance of the function to remove! It doesn't remove the original event listener.
  element.removeEventListener('ionViewWillEnter', this.ionViewWillEnter.bind(this)); 
}
```

The `.bind` method returns a new instance of the function. This means in
the implementation we are creating a new instance of the function when
both adding and removing the event listener - resulting in the
`removeEventListener` to never remove the original event listener.

This behavior only occurred in React 18 in dev mode, as a result of the
mount/unmount behavior running 2x for `useEffect` hooks.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Ionic lifecycle event listeners are removed from element references
when they are unmounted.
- User's lifecycle callback methods are only invoked once per event
emission.

|Before|After|
|----|----|
|<img alt="CleanShot 2023-10-09 at 18 32 08@2x"
src="https://github.com/ionic-team/ionic-framework/assets/13732623/53f2ef5d-5900-4a84-b427-fa6c9d35d081">|<img
alt="CleanShot 2023-10-09 at 18 29 37@2x"
src="https://github.com/ionic-team/ionic-framework/assets/13732623/c8a9a657-a0bf-4d6d-9f21-a41a686de490">|


## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

---------

Co-authored-by: Maria Hutt <maria@ionic.io>
Co-authored-by: Amanda Johnston <90629384+amandaejohnston@users.noreply.github.com>
2023-10-12 15:02:21 +00:00
59f23dcc2c chore(): update package lock files 2023-10-11 14:21:37 +00:00
053b7d59d3 v7.5.0 2023-10-11 14:21:18 +00:00
dc2f55f0fb chore: sync with main 2023-10-11 09:50:48 -04:00
2caaf6a526 chore(): update package lock files 2023-10-11 13:29:45 +00:00
cb47273f26 v7.4.4 2023-10-11 13:29:27 +00:00
b5261e0f41 Merge remote-tracking branch 'origin/main' into sync-feature-7.5-109 2023-10-09 15:42:31 -04:00
6da82aab81 feat(angular, react, vue, core): export openURL utility (#28295)
Issue number: resolves #27911 

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

The `openURL` utility is not available to developers. 

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Export `openURL` utilities from `@ionic/core`, `@ionic/angular`,
`@ionic/react` and `@ionic/vue`.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
2023-10-09 12:51:34 -04:00
2429caa168 chore(): update package lock files 2023-10-04 13:26:49 +00:00
a8517f4fcf v7.4.3 2023-10-04 13:26:30 +00:00
078964447a chore(): update package lock files 2023-09-27 13:32:44 +00:00
45bcd4c22b v7.4.2 2023-09-27 13:32:27 +00:00
de1a4c50bb test: update test apps to cypress 13 (#28212)
Issue number: N/A

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

CI is failing for Cypress apps due to
https://github.com/cypress-io/cypress/issues/27804#issuecomment-1721476731.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- All Cypress test apps have been updated to Cypress 13.2.0 which is not
affected by this issue.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
2023-09-21 20:17:46 +00:00
0edcb2cd85 fix(react): Nav unmounts component while invoking popTo or popToRoot (#27821)
Issue number: Resolves #27798

---------

## What is the current behavior

React IonNav component's views are missing keys, leading to unnecessary
duplicate mounting of components.


## What is the new behavior?
- Adds key to views of React IonNav component.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

---------

Co-authored-by: Sean Perkins <sean@ionic.io>
2023-09-20 17:31:58 +00:00
2e626a909f chore(): update package lock files 2023-09-20 13:21:09 +00:00
d82414d43f v7.4.1 2023-09-20 13:20:51 +00:00
6304645a81 chore(): update package lock files 2023-09-14 13:07:07 +00:00
c28b66a99a v7.4.0 2023-09-14 13:06:52 +00:00
d547944e91 Merge remote-tracking branch 'origin/main' into sync-final-74 2023-09-13 09:38:37 -04:00
af29857c5f chore(): update package lock files 2023-09-13 13:12:27 +00:00
f9a984e4aa v7.3.4 2023-09-13 13:12:09 +00:00
474308618d Merge remote-tracking branch 'origin/main' into sync-feat-74 2023-09-11 09:23:16 -04:00
19f3bb23fd feat: export TransitionOptions interface and getIonPageElement (#28140)
Issue number: resolves #28137

---------

Changes according to [this
comment](https://github.com/ionic-team/ionic-framework/issues/28137#issuecomment-1710283096)

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

@liamdebeasi Sorry for replacing the previous PR. I only copied the main
branch to my fork so I couldn't rebase properly. I am unfortunately not
extremely familiar with Github.

---------

Co-authored-by: Philipp Heuer <philipp@studysmarter.de>
Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>
2023-09-11 08:53:56 -04:00
7dbce4fc09 chore(): update package lock files 2023-09-06 13:24:04 +00:00
3de1dd3c14 v7.3.3 2023-09-06 13:23:50 +00:00
7b551fd54b fix(react): overlay content is shown with hook (#28109)
Issue number: resolves #28102

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

When one modal is added and another modal is removed, the modal that is
removed does not account for the newly added modal when updating the
overlay context in React. As a result, the inner contents of the newly
added modal is not mounted.

We originally tried to fix this in
https://github.com/ionic-team/ionic-framework/pull/24553, but the fix
was not complete. While storing the latest information in a React ref
was correct, the way we updated the ref was done in a way such that data
was still stale.

In particular, the `overlaysRef` is updated whenever `IonOverlayManager`
is re-rendered. State updates are batched, so updating the state twice
in quick succession does not necessarily result in 2 separate renders.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- We need to make sure the ref is updated synchronously before any
render so that `addOverlay` and `removeOverlay` always have access to
the latest data.
- Added a test

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.3.3-dev.11693592339.18e000af`

---------

Co-authored-by: Maria Hutt <thetaPC@users.noreply.github.com>
Co-authored-by: Amanda Johnston <90629384+amandaejohnston@users.noreply.github.com>
2023-09-05 21:04:27 +00:00
a25c38223c chore(): update package lock files 2023-08-30 12:48:07 +00:00
f9211e5434 v7.3.2 2023-08-30 12:47:53 +00:00
b333bdffe6 chore(): update package lock files 2023-08-23 13:40:28 +00:00
5701f7661e v7.3.1 2023-08-23 13:40:10 +00:00
0ac3df3f37 fix(react): avoid multiple invocations of onDidDismiss and onWillPresent (#28020)
Issue number: Resolves #28010

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

`onDidDismiss` and `onWillPresent` will fire twice when having a manual
binding in your implementation for inline overlays.

e.g.:
```tsx
<IonAlert onDidDismiss={() => console.log('hello world')} />
```

Will result in:
> hello world
> hello world

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- `onDidDismiss` and `onWillPresent` do not execute the callback handler
twice per invocation

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev-build: `7.3.1-dev.11692305436.16a4008f`
2023-08-22 14:23:04 +00:00
1015c06cbe chore(react): update sync script to use tgz (#28019)
Issue number: N/A

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

The sync script for the React package is out of date. It will
unintentionally delete the symlink directory of the build output from
`core/`, which breaks the build for the package during local
development.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Updates the sync script to package and install the `core` package 
- Matches the implementation pattern used for the sync script in our
other packages

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
2023-08-18 14:42:20 +00:00
6877d659d3 chore(): update package lock files 2023-08-16 14:23:51 +00:00
16f7ec2284 v7.3.0 2023-08-16 14:23:33 +00:00
7c24965216 chore(): update package lock files 2023-08-16 13:26:24 +00:00
ffe5307905 v7.2.4 2023-08-16 13:26:09 +00:00
3a263d14c3 chore(): update package lock files 2023-08-09 16:28:15 +00:00
0cb37430d3 v7.2.3 2023-08-09 16:27:57 +00:00
aa326a6eda chore(react): update v18 test app to use vite (#27935)
Issue number: N/A

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

React 17/18 test apps use react-scripts. This does not align with our
starter templates.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Updates the React 18 test app to use Vite
- Leaves the React 17 test app on react-scripts for now
- Updates test app dependencies to align with the react starters

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
2023-08-09 14:12:51 +00:00
1cf1eca002 fix(tab-button): update event type interface on React (#27950)
closes #27949

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

- Typescript is complaining about the `onClick` event type of the
`IonTabButton`

```ts
const App: React.FC = () => {
  async function handleTabClick(e: CustomEvent<HTMLIonTabButtonElement>) {
    alert(e.detail.tab);
  }

  return (
    <IonTabButton tab="myTab" onClick={handleTabClick}>
  );
};
```

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- `onClick` handler uses `CustomEvent` type
- Typescript does not error

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->




## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
2023-08-09 14:05:39 +00:00
01857dd315 chore(): update package lock files 2023-08-02 15:59:53 +00:00
dbe6f390ef v7.2.2 2023-08-02 15:59:37 +00:00
960adbbc5c chore(): update package lock files 2023-07-26 15:54:44 +00:00
db29871654 v7.2.1 2023-07-26 15:54:29 +00:00
08cc3d93ae chore(): update package lock files 2023-07-19 16:29:26 +00:00
8661e21674 v7.2.0 2023-07-19 16:29:12 +00:00
f18da214bc chore(): update package lock files 2023-07-19 13:08:31 +00:00
7e174849b5 v7.1.4 2023-07-19 13:08:11 +00:00
d6c812f785 chore(): update package lock files 2023-07-12 12:54:58 +00:00