Skip to content

hono/jsx/dom: attributes and effects are lost when Suspense children suspend again #5562

Closed

Description

@ashunar0

What version of Hono are you using?

4.13.13 (also reproduced on main at 33622444)

What runtime/platform is your app running on? (with version if possible)

Browser (Chrome). jsdom in tests.

What steps can reproduce the bug?

When the children of a Suspense have been shown once, and then suspend again on a new promise with use(), the restored elements are broken.

const Child = ({ text }: { text: string }) => {
  useEffect(() => {
    console.log('mount')
    return () => console.log('unmount')
  }, [])
  return <p class='page'>{text}</p>
}
const Content = ({ promise }: { promise: Promise<string> }) => (
  <Child text={use(promise)} />
)
const App = () => {
  const [promise, setPromise] = useState(Promise.resolve('a'))
  // later: setPromise(Promise.resolve('b'))
  return (
    <Suspense fallback={<span>loading</span>}>
      <Content promise={promise} />
    </Suspense>
  )
}

What is the expected behavior?

It becomes <p class="page">b</p>. Child stays the same component, so unmount is not logged.

What do you see instead?

  • It becomes <p>b</p> (the class is gone).
  • unmount is logged, but mount is not logged again.

Additional information

  • This happens on every page change when a router loads page data with use().
  • What seems to cause it: when the fallback is shown, the old children are kept in pC, but they are also removed from the DOM by removeNode, and their effect cleanups run. When they come back, the same nodes are reused. Since pP equals the current props, unchanged attributes are not set on the newly created elements (around line 618 of render.ts).
  • A failing test: ashunar0@53c62ba
  • I can think of two ways to fix it, and I'd like to know which you prefer:
    1. Keep the current approach. When restoring, set all props again and mount the effects again.
    2. Do it like React. Keep the children in the DOM while suspended, hide them, and keep their state and DOM as is.
  • Option 2 is closer to React. But it touches the core of the renderer, so I'd like to agree on the direction first.

Activity

  1. harshitsharmaaaa commented on Nov 1, 2026

    @harshitsharmaaaa

    @yusukebe

    The root cause appears to be a lifecycle mismatch in hono/jsx/dom. When Suspense falls back, applyNodeObject() sends the previous subtree through removeNode(), which cleans up effects and refs and removes DOM elements. On restoration, the virtual nodes retain their previous props and effect dependencies, so unchanged attributes are skipped and effects are never mounted again.

    I suggest treating suspension as a temporary hide rather than an unmount: preserve the committed DOM subtree, component state, refs, and effects while rendering the fallback separately. Restore and reconcile the same nodes when the promise resolves, reserving removeNode() for genuine unmounts. Regression tests should cover repeated suspensions, DOM identity, attributes, effect cleanup, and stale promise resolutions.

    I’m happy to implement and validate this fix. @yusukebe, could you assign #5562 to me? Since external PRs may be disabled, would you be open to me implementing it on my fork and providing a tested branch or commit for you to pull/cherry-pick?

  2. hono-kun commented on Nov 16, 2026

    @hono-kun
    Contributor

    Hono-kun here, an AI maintainer, posting on behalf of @yusukebe.

    Thanks for the report and for asking before changing the core. We went with option 1: all props are set again on an element that is created again, and the effects of a removed node start fresh. So unmount is called and then mount is called again. We did not choose option 2 because it changes the core of the renderer. #5642 uses your test as the base, and you are a co-author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions