●SUBDOMAIN — Rork can now connect your web app to a subdomain only, leaving your root domain and www untouched (12/1)●UPDATES — expo-updates 58.0.23 fixes Android release builds embedding a stale runtime version●FLASH END — Intro pricing for Gemini Flash models ends 12/31, 29 days from now. Time to recheck AI feature costs●HMR — Some report the dev server picking up another server's bundle and then exiting●FIRST VIEW — Map the first screen for a normal launch, a notification, and a link, and back navigation stops surprising you●CARBON — Gemini 4 Carbon and Argon are now at standard rates: $4.00 input, $20.00 output per 1M tokens●SUBDOMAIN — Rork can now connect your web app to a subdomain only, leaving your root domain and www untouched (12/1)●UPDATES — expo-updates 58.0.23 fixes Android release builds embedding a stale runtime version●FLASH END — Intro pricing for Gemini Flash models ends 12/31, 29 days from now. Time to recheck AI feature costs●HMR — Some report the dev server picking up another server's bundle and then exiting●FIRST VIEW — Map the first screen for a normal launch, a notification, and a link, and back navigation stops surprising you●CARBON — Gemini 4 Carbon and Argon are now at standard rates: $4.00 input, $20.00 output per 1M tokens
My Ads Never Came Back After a Subscription Expired: Fixing the Direction of an Ad-Free Check
An ad-free flag stayed on after the subscription expired because the check pointed the wrong way. Here is how I rebuilt it to wait for two purchase queries, decide only from confirmed facts, and keep the last value on failure.
I was writing out a decision flow line by line one night. One of my wallpaper apps, which I run as an indie developer, removes ads after a purchase. What I had never done, I realized, was trace what happens to that "ads removed" state after the subscription expires.
When I traced it, I stopped. The branch that brings ads back was not written anywhere.
What I had was a lapsed subscription with the ads still off. An ad shown to a paying user gets noticed fast and turns into a support message. The opposite accident, ads that stay off for someone who no longer pays, bothers nobody, so nobody reports it. It simply continues. I found it on the Android side, and it became the first item on the checklist I wrote before carrying the same logic over to iOS.
What I want to say first is that the fix was not about how to use a billing SDK. It was about the direction of the check and the way it waits. What follows is a write-up of that idea, rebuilt as code I could run, and then run.
One sentence that describes the bug: the direction was reversed
Put into words, the broken check read: "if the flag is not ad-free right now, set it to false." What it should have said was: "if no purchase is confirmed, set it to false." The subject was the flag's own current value instead of a confirmed fact.
I will not paste the original code. Here is the idea, reconstructed in TypeScript.
// adfree.ts — composing the ad-free flag from two purchase queriesexport type Source = "subscription" | "oneTime"; // subscription / one-time purchaseexport type QueryResult = | { ok: true; active: boolean } | { ok: false; reason: string };export type Results = Record<Source, QueryResult>;// A reconstruction of the broken direction (the idea, not a quote of the real code)export function applyBuggy(prev: boolean, r: Results): boolean { const purchased = (r.subscription.ok && r.subscription.active) || (r.oneTime.ok && r.oneTime.active); if (purchased) return true; if (!prev) return false; // "if not ad-free right now, set false": the direction is backwards return prev; // even after expiry, the previous true stays}
This code works correctly up to the moment a purchase is confirmed, which is why checking right after a purchase reveals nothing. It breaks only once, after the subscription lapses. When the query answers "none" and prev is still true, it keeps returning true.
Tests on the working side never find this kind of bug. "Buy it and the ads disappear" stays green no matter how often you repeat it. Test the direction that removes ads and the direction that brings them back separately. I put that at the top of my checklist.
Wait for both sources, then decide only from confirmed facts
There was not one purchase query but two, for example a subscription and a one-time purchase. If you set false the moment one source says "none", ads flash on screen when the other source is about to say "active".
I rewrote the decision as three rules.
Outcome of the two queries
Value to set
Why
At least one confirmed "active"
true
One piece of proof is enough, even if the other call failed
Both confirmed "inactive"
false
You may only clear the flag after hearing "inactive" from every source
A failure and no proof of active
keep the previous value
Do not manufacture an answer when you cannot decide
Here are those rules as a function.
// Fixed: decide only from confirmed facts; keep the previous value when undecidableexport function composeAdFree(prev: boolean, r: Results): boolean { const list = [r.subscription, r.oneTime]; // One confirmed "active" is enough, even if the other source failed if (list.some((x) => x.ok && x.active)) return true; // false only when every source confirmed "inactive" if (list.every((x) => x.ok && !x.active)) return false; // A failure and no proof of active: undecidable, so keep the previous value return prev;}
Why write it this way? The key is giving QueryResult a third state, "failed". active: false means "I asked and it was inactive". ok: false means "I could not ask". If both collapse into one false, a dropped connection becomes a change in billing state.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦You'll be able to check, with a table of two-source outcomes, whether your own app's ad-free flag really returns to false when a subscription lapses
✦You'll have a small decision function that waits for both queries, never invents an answer on a failed call, and can be unit-tested without your billing SDK
✦You'll avoid both opposite accidents before shipping: a paying user who briefly sees an ad, and a lapsed user whose ads never come back
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
With the function in place I laid out every combination and fed the same inputs to the broken version and the fixed one. This is the result from Node 22.
Case
Previous
Broken
Fixed
A Subscription expired, no one-time purchase
true
true (ads never return)
false
B Only the subscription query failed
true
true
true (previous kept)
C Subscription failed, one-time active
false
true
true
D Both failed, previous false
false
false
false
E Both failed, previous true
true
true
true
F Subscription active
false
true
true
The two versions differ only in case A. The whole bug lived in that one line. The other five rows exist to confirm that fixing it did not change anything else, and the table shows that at a glance.
A controller that stale responses cannot overwrite
The function alone was not enough. In a real app the check runs every time the app returns to the foreground and right after a purchase. When checks overlap, an older one can return late and overwrite a newer result.
First I reproduced the form that applies each source as it arrives.
// naive.ts — applying each source as it arrives (for reproduction)import type { QueryResult } from "./adfree.ts";export function makeNaive(initial: boolean, log: (s: string) => void) { let state = initial; return (r: QueryResult) => { const next = r.ok ? r.active : state; // decides from the one result that just arrived if (next !== state) { state = next; log(`naive -> ${next}`); } };}
Giving it a subscription "inactive" first and a one-time "active" afterwards produced naive -> false / naive -> true. Ads come back, then vanish again: a brief flicker for a paying user.
The fixed version gives the controller a generation number.
Inside refresh() it does three things: waits for both sources with Promise.all, turns a thrown exception into a "failed" value so nothing crashes, and discards its result if a newer refresh has started.
This is what I observed when I delayed and reordered the responses.
Situation
Result
Subscription returns "inactive" at 10 ms, one-time returns "active" at 40 ms
onChange never fires and the state stays true
Two refreshes in a row; the newer returns "inactive" first, the older returns "active" later
onChange(false) fires once; the stale response is discarded and the state stays false
The subscription query throws (one-time inactive)
No crash; the previous true is kept
The second row is my favorite. The old answer says active and the new answer says inactive. Which one is right is not decided by speed. A newer answer must never lose to an older one. A generation number keeps that promise with a single integer.
What counts as "inactive" differs by store
Everything above reads active: false as "I asked, and the answer was no." So when does a store query actually give you that answer? This is the point I had been vague about at first. Here are three misreadings, checked against the official documentation as of November 2026.
Misreading 1: an expired subscription comes back marked as expired. In Google Play Billing Library, queryPurchasesAsync() returns only active subscriptions and non-consumed one-time purchases (Android Developers, "Subscription lifecycle"). An expired subscription does not return with a new state; it simply drops out of the list. That means "not in the list" means inactive only when the query itself finished with BillingResponseCode.OK. Turn an empty list into false without looking at the response code, and a dropped connection becomes a lapse.
Misreading 2: you can ask about subscriptions and one-time purchases in one call. On Play, each query names a product type, SUBS or INAPP. The two sources in this article are not my design preference; they are the shape of the API. Ask only one and you miss case C in the table above, where the subscription query fails but the one-time purchase is active.
Misreading 3: purchase information you receive is always current. StoreKit 2's Transaction.currentEntitlements gives you the latest transactions that entitle the user, and it leaves consumables out (Apple Developer Documentation). The RevenueCat SDK caches CustomerInfo, so an answer from getCustomerInfo may come from that cache (RevenueCat Docs, "Caching"). In both cases there can be a window where "the value I got back" and "what is true right now" disagree. That is why the controller asks again every time the app returns to the foreground.
Play's own guide also recommends calling queryPurchasesAsync() when the app comes back to the foreground, in onResume(), because the purchase-update listener cannot be relied on to tell you about changes that happened outside the app. Re-asking on AppState in the Expo sketch is the same advice moved to the JavaScript side.
Decide where the merging lives before you write it
"Merge two sources" can live in three places. This is the table I drew up when I could not decide.
Where
How expiry is noticed
When the network drops
Effort
Fits when
On the device (this article's component)
A query on every return to the foreground
Keep the previous value
Small
Indie apps without a server, where the only entitlement is "no ads"
One RevenueCat entitlement
SDK and backend sync
Follow the SDK cache
Medium (dashboard setup)
You already use RevenueCat and want iOS and Android entitlements aligned
Your own server
Server notifications from the stores
Trust the server record
Large
Membership spans the web and the app, or you need fraud checks
The choice fits in one sentence. If the entitlement only removes ads and you run no server, merge on the device. If membership reaches beyond the app, or you already rely on a RevenueCat entitlement, let that layer do the merging and keep just one rule on the device: when a check could not be answered, keep the last value. Wherever the merging lives, that one rule still belongs on the device.
Even with RevenueCat, if you forget to attach both the subscription and the one-time product to the entitlement you use for ad-free, you are back to looking at only one source. It is worth opening the dashboard once and confirming that both products sit under that entitlement.
A sketch for wiring this into an Expo app
From here on it is a sketch whose types I have not checked and which I have not run on a device. I wrote it assuming an app generated with Rork could connect the same way.
// useAdFree.tsx — re-ask both sources whenever the app returns to the foreground (sketch, not run on a device)import { useEffect, useRef, useState } from "react";import { AppState } from "react-native";import AsyncStorage from "@react-native-async-storage/async-storage";import { AdFreeController, type QueryResult } from "./adfree";const KEY = "adfree:last";// Wrap your billing SDK calls here (report failures as ok:false)async function querySubscription(): Promise<QueryResult> { return { ok: false, reason: "not implemented" };}async function queryOneTime(): Promise<QueryResult> { return { ok: false, reason: "not implemented" };}export function useAdFree(): boolean { const [adFree, setAdFree] = useState(false); const ctl = useRef<AdFreeController | null>(null); useEffect(() => { let alive = true; (async () => { const saved = (await AsyncStorage.getItem(KEY)) === "1"; if (!alive) return; setAdFree(saved); ctl.current = new AdFreeController( { subscription: querySubscription, oneTime: queryOneTime }, saved, (v) => { setAdFree(v); AsyncStorage.setItem(KEY, v ? "1" : "0").catch(() => {}); }, ); await ctl.current.refresh(); })(); const sub = AppState.addEventListener("change", (s) => { if (s === "active") ctl.current?.refresh(); }); return () => { alive = false; sub.remove(); }; }, []); return adFree;}
What does it solve? It stores the last value on the device and uses it as the initial value at launch. When both queries are in, it replaces it. Until then, someone whose last value was true sees no ads, and someone whose last value was false does. The previous value decides how the app looks while it waits.
A troubleshooting table, starting from the symptom
Reports usually arrive as one line: "I'm seeing ads" or "the ads never came back." To get from that line to a cause, I keep this table.
Symptom
Likely cause
How to check
How to fix
Ads never return after the subscription lapses
The branch back to false reads the flag's own value instead of a confirmed fact
Run case A from the six-row table through your own decision function
Rewrite it as "false only when every source confirmed inactive"
A paying user sees an ad for a moment right after launch
The initial value is hard-coded to false and ads load before the checks finish
Launch in airplane mode on a device whose last value was true and watch the ad slot
Persist the last value as the initial state and initialize ads after the decision
Paying users see ads on days with a bad connection
A failed query or an empty list is being read as "inactive"
Make a query throw and run cases B and E
Carry failure as ok: false and keep the last value when you cannot decide
Ads disappear right after purchase, then come back
Each source is applied as it arrives, or a stale response overwrites a newer one
Swap the response order and log how often onChange fires
Wait for both sources, then merge; drop stale responses with a generation number
Ads only come back after the app is relaunched
The check runs once at launch and never again
Let the subscription lapse, then just bring the app to the foreground
Call refresh() on every return to the foreground
The first two rows point in opposite directions but share a root: deciding something before the checks are in. When you fix the first row, run the second row's input as well, so you know you have not tipped over to the other side.
Four places to trip
1. Do not give "none" and "could not ask" the same value. Folding false, undefined, and an exception into a single false turns a flaky connection straight into a billing-state change. Give failure its own place in the result type.
2. Write the returning-direction test first. Alongside "buying removes ads", write "expiry brings ads back" with equal weight. The broken version failed only in case A.
4. OR a time-limited ad pause on separately. If a rewarded ad pauses ads for a while, keep that as its own state and combine it with OR at the end. Mixed into the purchase decision, you can no longer tell which reason made it true when it expires.
The next place to trip: right after a restore
Once this component is in, the next thing worth watching is the "Restore Purchases" button. When someone on a new phone taps it, calling refresh() before the restore has finished can merge against the old purchase list, leaving the ad-free value unchanged. I added one line to my checklist: call refresh() again after the restore completes. Because of the generation number, calling it twice around a restore never lets the older answer win.
In your own app, find the place where the ad-free value goes back to false when no purchase is confirmed. If you cannot find it, you may be in the state I was in.
If you do find it, check once whether that branch reads a confirmed fact or the flag's own current value. Then replace the six-row table above with your own two sources and fill it in.
When a question could not be answered, do not invent the answer. I try to keep to that line even on days with a bad connection, and even on days when I would like the ads back.
What I ran here is the TypeScript component rebuilt from the idea and its automated tests, and nothing more. I have not included device behavior in the original Android app or a check against StoreKit on the iOS side.
Share
Thank You for Reading
Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.