Skip to content

fix(android): reject native ad load promise on failure - #873

Open
hoanggbao00 wants to merge 3 commits into
invertase:mainfrom
hoanggbao00:feat/android-native-ad-load-reject
Open

fix(android): reject native ad load promise on failure#873
hoanggbao00 wants to merge 3 commits into
invertase:mainfrom
hoanggbao00:feat/android-native-ad-load-reject

Conversation

@hoanggbao00

@hoanggbao00 hoanggbao00 commented Aug 5, 2026

Copy link
Copy Markdown

Description

Scope: Android NativeAd only. Other formats already report load failures via events.

Problem: NativeAd.createForAdRequest() never rejected on Android when the ad request failed, so .catch() never ran and the promise could hang.

Fix: Align with iOS — reject the load promise on failure.

Changes:

  • Reject from AdListener.onAdFailedToLoad (error-code-no-fill, error-code-invalid-request, …)
  • Reject when response ID is missing (ERROR_LOAD)
  • Settle the promise once (loadSettled)
  • Export NativeAdLoadError + docs for error handling

Motivation: apps need load failures to reject promptly so they can update UI, fire analytics, retry, or fall back to another provider, instead of waiting for a hung promise / timeout.

Banner / Interstitial / Rewarded / App Open already report failures via events — this gap is specific to Android native ads.

Related issues

Related to #755

Release Summary

fix(android): reject NativeAd load promise on failure (align with iOS)

Checklist

  • I read the Contributor Guide
    and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
  • My change includes tests;
    • e2e tests added or updated in __tests__e2e__
    • jest tests added or updated in __tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan

  • Invalid ad unit ID → promise rejects with error-code-invalid-request
  • No fill → promise rejects with error-code-no-fill
  • Valid ad unit → promise resolves with NativeAd
  • yarn test __tests__/nativeAd.test.ts
NativeAd.createForAdRequest(TestIds.NATIVE)
  .then(setNativeAd)
  .catch((error) => {
    console.error('Native ad failed to load', error);
    // error.code e.g. 'error-code-no-fill' | 'error-code-invalid-request' | 'ERROR_LOAD'
  });

…ng functionality

- Added error handling for `NativeAd.createForAdRequest`, rejecting promises on load failures.
- Updated `ReactNativeGoogleMobileAdsNativeModule` to manage ad loading and destruction more effectively.
- Enhanced documentation to reflect new error handling behavior and added details on `NativeAdLoadError`.
- Updated dependencies in `yarn.lock` for various packages.
@docs-page

docs-page Bot commented Aug 5, 2026

Copy link
Copy Markdown

To preview the documentation for this pull request, visit the following URL:

docs.page/invertase/react-native-google-mobile-ads~873

Documentation is deployed and generated using docs.page

…ation

- Included a code snippet demonstrating error handling for `NativeAd.createForAdRequest`.
- Clarified the types of errors that can occur during ad loading.
@CLAassistant

CLAassistant commented Aug 5, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ mikehardy
❌ hoanggbao00
You have signed the CLA already but the status is still pending? Let us recheck it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@dylancom
dylancom requested a review from mikehardy August 15, 2026 20:23
- Destroy the loaded NativeAd when response ID is missing before rejecting
- Reject Android loads with ERROR_LOAD to match iOS
- Keep LoadAdError.message from the SDK instead of canned mapped text
- Document createForAdRequest failures as promise rejects, not @throws
- Tighten NativeAdLoadError to code ERROR_LOAD and opaque optional userInfo
- Align native-ads docs and examples with the shared ERROR_LOAD contract
- Fix Jest load assertion for default requestAgent and ERROR_LOAD rejects
@mikehardy mikehardy added the CLA: blocked needs CLA signed before merge label Aug 17, 2026

@mikehardy mikehardy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good after the follow-up commit — approving on code review.

Cannot merge yet: the CLA is still unsigned. @hoanggbao00 please sign the Contributor License Agreement so we can merge: https://cla-assistant.io/invertase/react-native-google-mobile-ads?pullRequest=873

Pre-merge: a reviewer should also do a manual device smoke of native-ad load failure paths (invalid unit / no-fill) to confirm the Android promise rejects as expected; the Jest coverage only mocks the JS bridge.

@mikehardy

Copy link
Copy Markdown
Collaborator

Hope that wasn't too presumptious of me to just tack on a commit and push but your fix in general looked great and we can merge it with just those little tweaks and the CLA signed. Cheers!

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.42%. Comparing base (a34c7ba) to head (56d2131).
⚠️ Report is 246 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #873      +/-   ##
==========================================
+ Coverage   43.72%   44.42%   +0.70%     
==========================================
  Files          30       36       +6     
  Lines         549      671     +122     
  Branches      151      168      +17     
==========================================
+ Hits          240      298      +58     
- Misses        309      373      +64     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mikehardy

Copy link
Copy Markdown
Collaborator

iOS failing for unrelated reasons, this is good to go if we get a CLA sign from @hoanggbao00

@mikehardy mikehardy added the workflow: pending merge Waiting on CI or question responses to merge, but otherwise ready label Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA: blocked needs CLA signed before merge workflow: pending merge Waiting on CI or question responses to merge, but otherwise ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants