Best practices

Rules for fast, clean Pulse widgets, taken from how the renderer works.

Use these to check what bricksui gives you. Each rule comes from how the renderer and components actually work.

1. Use the highest-level component that fits#

Pick in this order: a Pulse pre-built (DataGrid, MetricCardStack, LineChart, bar charts), then a design-system component (Table, Select, Badge, Button), and only then build from Stack, Row and Text. Pre-builts already have the right layout, theme and behaviour.

Component names must exist in the registry. A made-up name fails when the widget renders. Icons use GenUIIcon, not Icon.

Note

Some components need children in a set shape. A Select needs one Select.Item child per option. Without them the dropdown is empty.

Select with options
{ "component": "Select",
  "props": {
    "selectedKey": "$localState.status",
    "children": [
      { "component": "Select.Item", "props": { "id": "open", "label": "Open" } },
      { "component": "Select.Item", "props": { "id": "pending", "label": "Pending" } }
    ] },
  "@on": { "change": [{
    "action": "set_local_state",
    "actionPayload": { "path": "status", "value": "$value" } }] } }

2. Theme classes, no bracket values#

Bracket classes like text-[#079455] or text-[13px] don't work in widgets. Use standard classes and theme tokens in className. Put any one-off size or colour in style.

Avoid
"className": "text-[13px] text-[#079455]"
Do
"className": "text-sm text-success-600"

3. Repeat with #each#

Use #each for lists. Keep JSONata children expressions short: past about 500 characters, switch to #each or a pre-built. Every expression has a 500 ms time limit.

Do
{ "component": "Row",
  "#each": { "source": "$data.tickets", "as": "t" },
  "props": { "children": [
    { "component": "Text", "props": { "children": "$t.customer" } },
    { "component": "Badge", "props": { "children": "$t.priority" } } ] } }

4. Show an empty state#

Use #if with #else so an empty list says so, instead of showing nothing.

Do
{ "component": "Stack",
  "#if": "$count($data.tickets) > 0",
  "props": { "children": [ ] },
  "#else": { "component": "Text", "props": { "children": "No open tickets" } } }

5. Don't build what's hidden#

A popup without #if is built on load, even while closed. For a side panel with its own data, use @asidePanels: its $data is fetched only when the panel opens, and open_panel passes in what it needs.

Do
"@asidePanels": {
  "ticket": {
    "content": {
      "component": "Stack",
      "$data": {
        "detail": { "@connector": "rest",
          "@config": { "url": "'/api/tickets/' & $props.ticketId" } } },
      "props": { "children": [
        { "component": "Text", "props": { "children": "$data.detail.subject" } } ] } } } }

6. Let the query sort, filter and limit#

Sorting or filtering inside the widget runs again on every render. Ask the data source to do it, and cap the rows.

Do
"tickets": {
  "@connector": "supabase",
  "@config": {
    "table": "tickets",
    "query": {
      "select": "id,customer,priority,status",
      "status": "eq.open",
      "order": "created_at.desc",
      "limit": "50" } } }

7. Work it out once#

If the same count or filter appears in several places, save it once when the data arrives. Put @on.dataSuccess on the data source itself.

Do
"tickets": {
  "@connector": "supabase",
  "@config": { "table": "tickets" },
  "@on": { "dataSuccess": [{
    "action": "set_local_state",
    "actionPayload": {
      "path": "highCount",
      "value": "$count($data.tickets[priority = 'high'])" } }] } }

Then read $localState.highCount wherever you need it.

dataSuccess runs on every data arrival: first load, each poll, each realtime update. Keep it small, and never refetch_data the same source inside its own dataSuccess. That loops forever.

8. Define each call once#

Declare each data source once in $data. Buttons refresh it with refetch_data instead of repeating the call. Use invoke_connector only for one-off writes like POST or PATCH.

Do
{ "component": "Button",
  "props": { "children": "Refresh" },
  "@on": { "press": [{
    "action": "refetch_data",
    "actionPayload": { "sources": ["tickets"] } }] } }

9. Chain dependent fetches through state#

A data source's @config can't read $data. To fetch B using a value from A: save the value with set_local_state in A's dataSuccess, read it from $localState in B's @config, then refetch_data B. Use set_local_state, not set_shared_state, so the order is guaranteed.

10. Realtime first, poll with care#

Realtime updates only when the data changes, but it works with supabase only. For rest, polling is the only live option. It costs a fetch every tick. The interval must be at least 1000 ms (default 5000).

Supabase
"@sync": { "strategy": "realtime" }
REST, if you must
"@sync": { "strategy": "poll", "interval": 10000 }

11. No secrets in the spec#

Specs get shared and pasted into chats. Never put API keys or tokens in the JSON. Use relative URLs like /api/tickets so the platform's own client adds the login.

Avoid
"headers": { "Authorization": "Bearer sk-..." }