Skip to content

How remote UI works: one real screen, JSON to pixels

Server-driven UIDeep dive9 min readMiniwall team

Part of the series: Server-driven UI: a field guide for app teams

On this page

A remote UI is two things: a document that describes a screen, and a renderer that already shipped inside your app. The server sends the document. The device does the rest. It fills in what only it knows (the price, the language, the fonts), lays the screen out at its own width, draws it, and hands every tap back to your code.

The idea itself is covered in what server-driven UI is and, end to end, in the server-driven UI field guide. This post is narrower. It follows one real screen through each step and shows what can go wrong at each.

The screen is a trimmed copy of a "limited-time offer" template, in the format our own renderer reads (we make Miniwall, more on that at the end). We ran every step below against the published @miniwall/web 0.1.0, in Node 22 and in Chromium. Other formats use other field names. The steps don't change much.

Steps in order, with who does each: Server or Device.

  1. Server: Publish: check every field
  2. Server: Serve JSON with an ETag
  3. Device: Fetch, or reuse the saved copy
  4. Device: Fill in text and prices
  5. Device: Lay out and draw
  6. Device: Tap: your code runs
  7. Server: Record view and purchase
Where each step runs. The server checks and serves; everything after the fetch happens on the device. Shape only, not data.

The screen we'll follow

A title, one plan card with a price, and a buy button. Here it is with the colors, padding and sizes taken out, and two wrapper stacks flattened so it fits on a page:

come-back-to-pro.json (style fields removed)
{
  "default_locale": "en_US",
  "components_config": {
    "base": {
      "stack": {
        "type": "stack", "dimension": { "type": "vertical" }, "spacing": 20,
        "components": [
          { "type": "text", "text_lid": "text_lid_a9j35i" },
          {
            "type": "package", "package_id": "annual", "is_selected_by_default": true,
            "stack": {
              "type": "stack",
              "dimension": { "type": "horizontal", "distribution": "space_between" },
              "components": [
                { "type": "text", "text_lid": "text_lid_n2l238" },
                { "type": "text", "text_lid": "text_lid_exz7z7" }
              ]
            }
          },
          {
            "type": "purchase_button", "method": { "type": "in_app_checkout" },
            "stack": { "type": "stack", "components": [{ "type": "text", "text_lid": "text_lid_unuwc9" }] }
          }
        ]
      }
    }
  },
  "components_localizations": {
    "en_US": {
      "text_lid_a9j35i": "Come back to Pro",
      "text_lid_n2l238": "Yearly",
      "text_lid_exz7z7": "{{ product.price_per_period }}",
      "text_lid_unuwc9": "Claim offer"
    }
  }
}

Three things are missing on purpose. No text lives in the tree, only IDs that point into a table of strings per language. No price appears anywhere, only package_id: "annual" and a placeholder. And the button doesn't say what buying means. It says purchase_button and nothing about a checkout URL or a product ID in your billing system. Each of those gaps gets filled on the device, by a different party.

Step 1: fetch, or use what you already have

The device asks for a placement, not a screen: GET /v1/sdk/placements/upgrade_button?key=pk_.... The answer wraps the screen in an envelope with paywallId, a published version number, the screen itself, and packages, the list of package IDs your code must price[1]. For our screen that list is ["annual"].

The response carries an ETag and Cache-Control: public, max-age=0, s-maxage=30, stale-while-revalidate=30[1]. Read that header carefully. max-age=0 means a browser cache can't reuse it without checking first. s-maxage=30 lets a CDN hold it for half a minute. So a publish reaches devices within about a minute, and an unchanged screen costs a 304 with no body when the client sends If-None-Match[2].

The SDK also keeps its own copy, in localStorage on the web. If the network fails, the request times out (8 seconds by default) or the server answers 5xx, it uses that copy. A 4xx, like a wrong key or an unknown placement, is an error even when a copy exists[2]. That split is worth copying into any client you build. A 5xx says "try again later", so an old screen is a fair answer. A 4xx says "you asked for the wrong thing", and an old screen would hide the mistake.

What to cache, for how long, and what to do when there's no copy at all is its own topic: see caching remote screens.

Step 2: check it before you trust it

There are two checks, and they do different jobs.

The strict one runs at publish time. The editor shows what blocks publishing (a plan card without a package ID, a button without an action ID), and the server runs the same checks again before it accepts a publish[3]. Doing it on the server matters: a client that skips the editor's checks still can't put a broken screen in front of users.

The loose one runs on the device, and it mostly checks shape. Hand the web SDK an object without components_config.base and it throws Not a paywall JSON: expected components_config.base. We tried it. That's all the device should do here. By the time JSON reaches a phone, a failed check has no one to report to, and the useful question is "can I draw anything sensible?"

The harder case is a node the renderer doesn't know. Say next year's editor adds a component and an old app meets it. The rule in this format is: draw the node's fallback if it has one, otherwise leave the node out, and never crash[4]. We added a "type": "hologram" node to our screen. The web SDK drew the other four strings and skipped it. Given a fallback text node, it drew the fallback in its place. If you design a format, decide this rule before the first app ships, because every installed version holds you to it. JSON vs a DSL vs components goes into why the choice of format makes this easier or harder.

The version number from step 1 isn't used for drawing. It's there so every event later can say exactly which published version someone saw.

Step 3: fill in what only the device knows

Now the renderer walks the tree. Each text node swaps its text_lid for the string in the visitor's language. Ask for a locale the screen has no strings for (fr_FR, here) and it falls back to default_locale, so our French visitor sees "Come back to Pro".

Then come the placeholders. {{ product.price_per_period }} is filled from prices your code passes in, keyed by package ID. The SDK exports the helper it uses, so you can see the values before anything is drawn:

prices.mjs (Node 22, @miniwall/web 0.1.0)
import { buildProductVariables } from '@miniwall/web';

const vars = buildProductVariables(
  { annual: { price: 59.99, currency: 'USD', period: 'year' } },
  'en_US',
);
console.log(vars.annual['product.price_per_period']); // $59.99/year
console.log(vars.annual['product.price_per_month']);  // $5.00

The second line is 59.99 divided by 12, rounded. The output has 17 values for one package, from product.price to product.periodly ("yearly"); the docs list them all[5].

Why not put the price in the JSON? Because the price already lives somewhere else: your billing system, your store listing. A copy in the screen is a second source of truth that goes stale the day finance changes a price. The screen says which plan, your code says how much. If your code forgets one, the card shows without a price and the web SDK logs No price for package(s) annual[5]. We saw exactly that: "Yearly" with an empty space on the right.

One thing that caught our eye while testing. A placeholder with no value becomes an empty string, not an error. We changed the title to Hi {{ custom.first_name }}, come back and left the value out. The screen said "Hi , come back". With customVariables: { first_name: 'Ana' } it said "Hi Ana, come back". Silent blanks are the right call for a renderer (a crash is worse), but they move the burden to whoever writes the copy. Write lines that still read well when a variable is empty, or don't use the variable.

Step 4: layout happens on the device, at the device's width

The JSON never says where anything goes in pixels. It says "a vertical stack with 20 between children", "a horizontal stack, spread to both ends", "fill the width", "fit the content". The device turns that into its own layout system.

On the web you can watch it happen in devtools. Our plan card's inner stack (horizontal, space_between, spacing: 12) came out as display: flex; flex-direction: row; justify-content: space-between; gap: 12px. The root stack got flex-direction: column and gap: 20px. On iOS and Android the same words map to native layout instead.

This is the step where most of a renderer's effort goes, and it's easy to underestimate. "Space between" is simple. "Fill the width inside a stack that fits its content inside a scroll view" is where two platforms can quietly disagree, and nobody notices until a screen looks right on one phone and clipped on another. If you're building your own, keep a set of reference screens with expected images for each platform and compare them on every change. It's dull work, and it's the most reliable way we know to catch those disagreements.

Step 5: draw it inside a wall

On the web the screen draws in a shadow root, so your site's CSS can't break it and its CSS can't leak onto your page[6]. Text is escaped before markdown turns into HTML[6]. We set the title to <img src=x onerror=alert(1)> **Pro**. The page showed that tag as plain text, then "Pro" in bold. No image element was created and nothing ran.

Fonts are part of drawing, and they're slower than you'd think. A screen can name a font like Fraunces@700 and point it at a file. The web SDK only loads font files over https[6]. When we passed an http URL, the helper fontsFromPaywall simply left that font out. Phones can't read web font files, so the mobile SDKs download TrueType files instead and wait at most 6 seconds for each before falling back to the system font at the same weight[7]. A fallback font is a fine failure. A blank screen waiting on a font isn't.

Here's how the whole thing is wired up on a page, with our screen as a local JSON file:

pricing.js (@miniwall/web 0.1.0)
import { mountPaywall } from '@miniwall/web';
import screen from './come-back-to-pro.json' with { type: 'json' };

await mountPaywall(document.getElementById('pricing'), {
  paywall: screen,
  products: { annual: { price: 59.99, currency: 'USD', period: 'year' } },
  onPurchase: async ({ packageId, product }) => {
    // Your checkout. Return true when bought, false when cancelled, throw on failure.
    return startCheckout(packageId, product);
  },
});

startCheckout is yours. We ran the same call through the SDK's script-tag build in Chromium, with a stub for checkout.

Step 6: the tap goes back to your code

When we clicked "Claim offer", the SDK called onPurchase with packageId: 'annual' and the product we had passed in. That's the whole contract. The screen picks which package is selected; your code decides what buying it means: a Stripe Checkout redirect, an in-app purchase, a call to your own API.

This is the line we'd defend hardest in any remote UI design. The JSON names an intent (purchase_button, an action ID) and never carries the behaviour itself. If it could carry a URL to post card details to, or a script, then anyone who can publish a screen could change what your app does with money. Keep actions as names your code has registered, and the worst a bad publish can do is look wrong.

The result also feeds analytics. For a screen loaded by placement, the SDK sends view when it shows, purchase_click on the tap, and purchase, purchase_cancel or purchase_error depending on what your onPurchase returned. Events go in batches of up to 50 about two seconds after they happen, and on the web also when the page is hidden, using sendBeacon[8]. Each event carries the paywallId and version from step 1. A screen passed in as raw JSON, like ours, sends nothing; when we ran it, the page made no network requests at all. Which of those events you can trust, and which get lost, is covered in tracking remote UI events.

When you don't need all six steps

Most of this machinery exists because the screen has prices, buttons and several platforms. If what you change remotely is a headline and a color, a remote config value and code in the app is less to own. If the screen is one web page, server-rendered HTML gives you the same "change without a release" with no renderer at all. You need the full pipeline when the same screen has to look right in a browser and in native apps you can't redeploy on demand, and when non-developers will publish it.

Sources

Go further