fix(telegram): evaluate native-dialog availability at fire time
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 17s
CI / ui (pull_request) Successful in 56s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m27s

The deep-link info modals (stale invite, welcome-on-redeem) captured
insideTelegram() && telegramDialogsAvailable() in a const at component init, but they
mount in App before bootstrap loads the SDK, so the value was always false and they
fell back to the in-app Modal even inside Telegram. Evaluate it at fire time (in the
effect and the {#if} guard), as the destructive confirms already do at click time.
This commit is contained in:
Ilia Denisov
2026-06-24 13:16:11 +02:00
parent 2ba7cc3086
commit 4f0cc81dfb
2 changed files with 14 additions and 18 deletions
+7 -9
View File
@@ -11,10 +11,6 @@
// Split the message around the {bot} token so the bot handle renders as an inline link.
const parts = $derived(t('friends.staleInvite').split('{bot}'));
// Inside the Mini App with native popups, present the notice as Telegram's own popup instead of
// the in-app modal.
const useNative = insideTelegram() && telegramDialogsAvailable();
function openBot() {
if (username) {
const url = `https://t.me/${username}`;
@@ -25,12 +21,14 @@
dismissStaleInvite();
}
// Native path: raise Telegram's popup when the notice appears; its "open bot" button opens the
// bot chat, any other dismissal just clears the notice. The `shown` guard fires it once per notice.
// Native path: when the notice fires inside the Mini App with native popups, present Telegram's
// own popup instead of the in-app modal. insideTelegram()/dialogs are evaluated at fire time, not
// captured at init: this component mounts before bootstrap loads the SDK, so a captured value
// would be stale. The popup's "open bot" button opens the bot chat; any other dismissal clears the
// notice; the `shown` guard fires it once per notice.
let shown = false;
$effect(() => {
if (!useNative) return;
if (app.staleInvite && !shown) {
if (app.staleInvite && !shown && insideTelegram() && telegramDialogsAvailable()) {
shown = true;
void telegramShowPopup(
botInfoPopup(t('friends.staleInviteTitle'), t('friends.staleInvite'), username ?? '', t('common.ok')),
@@ -41,7 +39,7 @@
});
</script>
{#if app.staleInvite && !useNative}
{#if app.staleInvite && !(insideTelegram() && telegramDialogsAvailable())}
<Modal title={t('friends.staleInviteTitle')} onclose={dismissStaleInvite}>
<p class="msg">{parts[0]}{#if username}<button type="button" class="bot" onclick={openBot}>@{username}</button>{/if}{parts[1] ?? ''}</p>
<button class="ok" onclick={dismissStaleInvite}>{t('common.ok')}</button>
+7 -9
View File
@@ -14,10 +14,6 @@
// as an inline link (the {name} value is substituted first; {bot} is left for the split).
const parts = $derived(t('friends.welcomeRedeem', { name }).split('{bot}'));
// Inside the Mini App with native popups, present the greeting as Telegram's own popup instead of
// the in-app modal.
const useNative = insideTelegram() && telegramDialogsAvailable();
function openBot() {
if (username) {
const url = `https://t.me/${username}`;
@@ -28,12 +24,14 @@
dismissWelcomeRedeem();
}
// Native path: raise Telegram's popup when the greeting appears; its "open bot" button opens the
// bot chat, any other dismissal just clears it. The `shown` guard fires it once per greeting.
// Native path: when the greeting fires inside the Mini App with native popups, present Telegram's
// own popup instead of the in-app modal. insideTelegram()/dialogs are evaluated at fire time, not
// captured at init: this component mounts before bootstrap loads the SDK, so a captured value
// would be stale. The popup's "open bot" button opens the bot chat; any other dismissal clears it;
// the `shown` guard fires it once per greeting.
let shown = false;
$effect(() => {
if (!useNative) return;
if (app.welcomeRedeem && !shown) {
if (app.welcomeRedeem && !shown && insideTelegram() && telegramDialogsAvailable()) {
shown = true;
void telegramShowPopup(
botInfoPopup(t('friends.welcomeRedeemTitle'), t('friends.welcomeRedeem', { name }), username ?? '', t('common.ok')),
@@ -44,7 +42,7 @@
});
</script>
{#if app.welcomeRedeem && !useNative}
{#if app.welcomeRedeem && !(insideTelegram() && telegramDialogsAvailable())}
<Modal title={t('friends.welcomeRedeemTitle')} onclose={dismissWelcomeRedeem}>
<p class="msg">{parts[0]}{#if username}<button type="button" class="bot" onclick={openBot}>@{username}</button>{/if}{parts[1] ?? ''}</p>
<button class="ok" onclick={dismissWelcomeRedeem}>{t('common.ok')}</button>