Skip to content

Reactivity fails using State management in native app using perry/ui #8046

Description

@h2atecnologia

What happened

I tried running the attached code, and the reactivity of the variable used as State shows undefined in the UI, as does console.log() when the Add button was clicked.

If I use ""+ count.value or String(count.value), the UI shows the freezed initial value 3 but the console.log() shows the state.value incremented by 1.

What you expected

The expectation was that the UI would refresh the Text content in the UI just like with console.log() when the Add button was clicked.

Minimal reproduction

Compile, run counter app. Hit the Add button and you'll see the console showing undefined and on countrer app screen, Hello from Perry! undefined

import { App, Text, Button, VStack, State } from "perry/ui"

const count = State(3)
App({
    title: "My App",
    width: 400,
    height: 300,
    body: VStack(16, [
        Text(`Hello from Perry! ${ count.value }`),
        Button("Add", () => { 
          count.set( count.value + 1 ); 
          console.log(count.value);
        },
{
    backgroundColor: { r: 0.231, g: 0.510, b: 0.965, a: 1.0 },
    borderColor: { r: 0.0, g: 0.0, b: 0.0, a: 0.1 },
    borderWidth: 1,
    borderRadius: 8,
    padding: 12,
    opacity: 0.95,
    shadow: {
        color: { r: 0.0, g: 0.0, b: 0.0, a: 0.25 },
        blur: 12,
        offsetX: 0,
        offsetY: 4,
    },
    tooltip: "Save the current document",
    enabled: true,
}
)
    ]),
})

Command you ran:

perry compile counter.ts -o counter

Environment

  • Perry version: 0.5.1220
  • Host OS: macOS 15.7.7
  • Target: native
  • Rust toolchain: n/a
  • Installed via: brew

Diagnostic output

Perry Doctor

Environment Checks
──────────────────
✓ perry version: 0.5.1220
✓ update status: up to date
✓ clang (LLVM codegen): Apple clang version 17.0.0 (clang-1700.6.4.2)
✓ system linker (cc): Apple clang version 17.0.0 (clang-1700.6.4.2)
✓ runtime library: /opt/homebrew/lib/libperry_runtime.a
✓ project config (perry.toml): found
✓ compatibility reports (#849): mode=ask (sent=0, suppressed-by-dedup=0, queued=0, cache=empty)

All checks passed!

Anything else

perry compile counter.ts -o counter 
Collecting modules...
  Package alias: react → perry-react
  Package alias: react-dom → perry-react
  Package alias: react-dom/client → perry-react
  Package alias: react/jsx-runtime → perry-react
Found 1 module(s): 1 native, 0 JavaScript
Generating code...
Reused cached object: /Users/henrique/node/poc-perryts/node_modules/.cache/perry/objects/host/86e5653ac45e4404.o
Linking (runtime-only)...
[strip-dedup] Processing: /opt/homebrew/lib/libperry_ui_macos.a
[strip-dedup] ar found: /usr/bin/ar
[strip-dedup] libperry_ui_macos.a: 431 total members
[strip-dedup] libperry_stdlib.a found: /opt/homebrew/Cellar/perry/0.5.1220/lib/libperry_stdlib.a — 1234 members loaded
[strip-dedup] libperry_runtime.a found: /opt/homebrew/Cellar/perry/0.5.1220/lib/libperry_runtime.a — 113 members loaded
[strip-dedup] Total exclude set: 1347 members from stdlib+runtime .lib files
[strip-dedup] rlib NOT found: /opt/homebrew/lib/libperry_ui_macos.rlib
[strip-dedup] libperry_stdlib.a symbols loaded: 0
[strip-dedup] libperry_runtime.a symbols loaded: 0
[strip-dedup] libperry_ui_macos.a: keeping 200 of 431 members (excluded: 0 by symbol-subset, 231 by name pattern)
[strip-dedup] Building trimmed libperry_ui_macos.a: 200 objects total
[strip-dedup] ERROR: archive creation failed: ar: /var/folders/9j/337r8c1s0713xfmkkzvyf9qh0000gn/T/perry_strip_96024/_libperry_ui_macos.a_extract/__.SYMDEF: Permission denied

[strip-dedup] skipped for UI lib (non-fatal): Failed to create trimmed archive for libperry_ui_macos.a: ar: /var/folders/9j/337r8c1s0713xfmkkzvyf9qh0000gn/T/perry_strip_96024/_libperry_ui_macos.a_extract/__.SYMDEF: Permission denied

Linking perry/ui (native UI) from /opt/homebrew/lib/libperry_ui_macos.a
ld: warning: duplicate symbol '_rust_eh_personality' in:
    /opt/homebrew/Cellar/perry/0.5.1220/lib/libperry_ui_macos.a[39](std-17ed52d55cdc389f.std.93770f9ee7fea9f3-cgu.0.rcgu.o)
    /Users/henrique/perry/target/perry-auto-ee47744fef260b8c/release/libperry_runtime.a[65](perry_runtime-644711cd88bb7f4a.std-4f24f0876fd27385.std.7648081134ee26d8-cgu.0.rcgu.o.rcgu.o)
Wrote executable: counter
Binary size: 5.8MB
Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions