Skip to content

Commit

Permalink
fix: teardown happening during initial setup (#134)
Browse files Browse the repository at this point in the history
## Description
This fixes an issue that can occur if the AdvertisingProvider unmounts
during the initial GPT setup.

I've added a new state value (isInitialSetupComplete), which gets set
when the setup completes and prevents `omponentWillUnmount` from calling
the teardown function. This ensures we don't create a race condition
between the setup and teardown, which can break the display ads.

Co-authored-by: Stephen Gill <[email protected]>
  • Loading branch information
caffeinated-pixels and Stephen Gill authored Feb 6, 2024
1 parent ff666ef commit 47f515e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/AdvertisingProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class AdvertisingProvider extends Component {
this.state = {
activate: this.advertising.activate.bind(this.advertising),
config: this.props.config,
isInitialSetupComplete: false,
};
}

Expand Down Expand Up @@ -66,7 +67,11 @@ export default class AdvertisingProvider extends Component {
}

async componentWillUnmount() {
if (this.props.config) {
/**
* Prevent the teardown call while initial setup still in progress
* otherwise it can create a race condition that breaks the setup process
*/
if (this.props.config && this.state.isInitialSetupComplete) {
await this.teardown();
}
}
Expand Down

0 comments on commit 47f515e

Please sign in to comment.