ShoppingateShoppingateDevelopers
shoppinggate.app ↗
Documentation
  • What is a Mini App
  • Why Mini Apps
  • API integration
  • SDK
  • Webview
  • Mini App architecture
  • Getting started
  • Choosing your path
  • Introduction
    • Introduction
    • Sign up & login
    • Dashboard & analytics
    • Mini-Programs
    • Submit & publish a version
    • App Binding
    • Privacy Settings
    • Allowed URL
    • Users & roles
    • Introduction
    • Become a Mini-App vendor
    • API keys
    • My Mini-Apps
    • Orders
    • Webhook
    • Deep-link config
    • Introduction
    • Install & log in
    • Create a project
    • The workspace
    • Preview & upload
  • Introduction
  • Configuration
  • Lifecycle
  • Routing & query
  • Host functions
  • orderPayment
  • Permissions
  • User info
  • Introduction
  • Configuration
  • SDK
  • Lifecycle
  • Routing & query
  • Host functions
  • orderPayment
  • Permissions
  • User info
  • Web app and shell calls
  • Look and feel
  • Overview
    • Verify user
    • Create order
    • Get order
    • Update order status
    • Charge an order
    • Send a notification
  • Subscriptions
    • Create a subscription
    • List subscriptions
    • Get a subscription
    • Update a subscription
    • Reschedule next charge
    • Change plan (upgrade)
    • Cancel a subscription
  • Webhooks
Web view mini-app

Lifecycle

A web view Mini App has two lifecycles: the shell mini-app's, and your web app's. This page covers your web app's — what it can listen for, and what belongs in each.

Two lifecycles

What runs
The shell mini-app
The same App and Page hooks as a native Mini App — onLaunch, onShow, onHide, onLoad and the rest. See Native mini-app → Lifecycle.
Your web app
Three events from the SDK — ft.miniProgram.onShow, onHide and onUnload — plus your normal browser events.

Your web app's events

Your web app is a web page, so browser events like load run once, when it first opens. They don't tell you when the user leaves and comes back. The SDK adds three events for that:

Event
Fires when
Use it to
ft.miniProgram.onShow
Your web app becomes visible again — the user comes back from another page, or returns to the Shoppingate app.
Refresh anything that may have changed while it was hidden.
ft.miniProgram.onHide
Your web app is hidden — another page opens over it, or the user leaves the Shoppingate app.
Pause timers, video and anything that doesn't need to run.
ft.miniProgram.onUnload
The page holding your web app is closed.
Save what must not be lost.

Register them

Register each event once, when your web app starts:

// Register once, when your web app starts — not on every render.
if (window.ft && ft.miniProgram) {
  ft.miniProgram.onShow(function () {
    // Your web app is visible again — refresh what may have changed.
    refreshUserAndCart();
  });

  ft.miniProgram.onHide(function () {
    // Your web app is no longer visible — pause what doesn't need to run.
    pauseTimersAndMedia();
  });

  ft.miniProgram.onUnload(function () {
    // The page holding your web app is closing — save what must not be lost.
    saveDraft();
  });
}

In a React web app, do it once in your top-level component:

// React — register once, in your top-level component.
import { useEffect } from 'react';

export default function App() {
  useEffect(() => {
    if (!window.ft || !ft.miniProgram) return; // opened outside the Mini App

    ft.miniProgram.onShow(() => refreshUserAndCart());
    ft.miniProgram.onHide(() => pauseTimersAndMedia());
    ft.miniProgram.onUnload(() => saveDraft());
  }, []); // [] — once, on start

  return <Routes />;
}
Check for ft first. It only exists inside the Mini App. Opened in a normal browser, there is no ft, and calling it would throw. See SDK → Knowing you are inside a web view.

Tell the shell your web app has loaded

When your web app has finished loading, call ft.complete(). If the shell sets a load timeout for the web-view, a web app that never calls it is treated as having failed — no matter how well it rendered. See SDK.

Which one to use

You want to…
Use
Set things up once, when your web app first opens
Your normal start-up code, or browser load
Refresh data every time the user comes back
ft.miniProgram.onShow
Pause timers or media when the user leaves
ft.miniProgram.onHide
Save work before the page closes
ft.miniProgram.onUnload
Know the Mini App opened or came to the foreground
The shell's App.onLaunch / App.onShow — see Native → Lifecycle