[GH-ISSUE #131] Changing variables not re-rendering #30

Closed
opened 2026-03-02 23:43:59 +03:00 by kerem · 4 comments
Owner

Originally created by @k2on on GitHub (Sep 3, 2025).
Original GitHub issue: https://github.com/anomalyco/opentui/issues/131

Originally assigned to: @msmps on GitHub.

I am trying to use Zero Sync Engine like this:

import { useQuery, useZero, ZeroProvider } from "@rocicorp/zero/react";
import { schema, Schema } from "./schema";

function App() {
  const z = useZero<Schema>();
  const [messages] = useQuery(z.query.message);

  return (
    <box>
	{messages.map(m => <box>
	  <text>{m.body}</text>
	</box>)}
    </box>
  )
}

This code works using ink, but not with OpenTUI.

However, this does work with OpenTUI when I add some other state, such as this

import { useQuery, useZero, ZeroProvider } from "@rocicorp/zero/react";
import { schema, Schema } from "./schema";

function App() {
  const z = useZero<Schema>();
  const [messages] = useQuery(z.query.message);

  // adding this will fix it
  useEffect(() => {
    const interval = setInterval(() => {
      setCounter((prevCount) => prevCount + 1)
    }, 60)
    return () => clearInterval(interval)
  }, []);

  return (
    <box>
	{messages.map(m => <box>
	  <text>{m.body}</text>
	</box>)}
    </box>
  )
}

Any idea on why messages wouldn't rerender by itself?

Thanks for the help,
Max

Originally created by @k2on on GitHub (Sep 3, 2025). Original GitHub issue: https://github.com/anomalyco/opentui/issues/131 Originally assigned to: @msmps on GitHub. I am trying to use [Zero Sync Engine](https://zero.rocicorp.dev) like this: ```tsx import { useQuery, useZero, ZeroProvider } from "@rocicorp/zero/react"; import { schema, Schema } from "./schema"; function App() { const z = useZero<Schema>(); const [messages] = useQuery(z.query.message); return ( <box> {messages.map(m => <box> <text>{m.body}</text> </box>)} </box> ) } ``` This code works using [ink](https://github.com/vadimdemedes/ink), but not with OpenTUI. However, this does work with OpenTUI when I add some other state, such as this ```tsx import { useQuery, useZero, ZeroProvider } from "@rocicorp/zero/react"; import { schema, Schema } from "./schema"; function App() { const z = useZero<Schema>(); const [messages] = useQuery(z.query.message); // adding this will fix it useEffect(() => { const interval = setInterval(() => { setCounter((prevCount) => prevCount + 1) }, 60) return () => clearInterval(interval) }, []); return ( <box> {messages.map(m => <box> <text>{m.body}</text> </box>)} </box> ) } ``` Any idea on why messages wouldn't rerender by itself? Thanks for the help, Max
kerem 2026-03-02 23:43:59 +03:00
  • closed this issue
  • added the
    bug
    react
    labels
Author
Owner

@msmps commented on GitHub (Sep 3, 2025):

I will look into this! It looks like the useQuery(z.query.message); hook is not triggering a re-render in this specific scenario which is odd 🤔

A quick (although not ideal) workaround would be to hand over control of the rendering loop to opentui by setting the live prop on the parent <box>

<!-- gh-comment-id:3250609761 --> @msmps commented on GitHub (Sep 3, 2025): I will look into this! It looks like the `useQuery(z.query.message);` hook is not triggering a re-render in this specific scenario which is odd 🤔 A quick (_although not ideal_) workaround would be to hand over control of the rendering loop to opentui by setting the `live` prop on the parent `<box>`
Author
Owner

@k2on commented on GitHub (Sep 3, 2025):

Ok, thanks for looking into this. I would love to switch over from Ink so getting this to work with zero would be really huge. Thanks for the help.

<!-- gh-comment-id:3250723259 --> @k2on commented on GitHub (Sep 3, 2025): Ok, thanks for looking into this. I would love to switch over from Ink so getting this to work with zero would be really huge. Thanks for the help.
Author
Owner

@remorses commented on GitHub (Sep 3, 2025):

Probably an issue with useSyncExternalStore

github.com/rocicorp/mono@cbdfefe899/packages/zero-react/src/use-query.tsx (L82)

<!-- gh-comment-id:3250751260 --> @remorses commented on GitHub (Sep 3, 2025): Probably an issue with useSyncExternalStore https://github.com/rocicorp/mono/blob/cbdfefe899f984c82d07aeb414d43981fb33b048/packages/zero-react/src/use-query.tsx#L82
Author
Owner

@msmps commented on GitHub (Sep 3, 2025):

Probably an issue with useSyncExternalStore

github.com/rocicorp/mono@cbdfefe899/packages/zero-react/src/use-query.tsx (L82)

this is the outcome i had landed on (for now) will investigate in the coming days

<!-- gh-comment-id:3250947155 --> @msmps commented on GitHub (Sep 3, 2025): > Probably an issue with useSyncExternalStore > > https://github.com/rocicorp/mono/blob/cbdfefe899f984c82d07aeb414d43981fb33b048/packages/zero-react/src/use-query.tsx#L82 this is the outcome i had landed on (_for now_) will investigate in the coming days
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#30
No description provided.