Skip to content

Conversation

@gbj
Copy link
Collaborator

@gbj gbj commented Nov 12, 2025

Currently, Suspense only tracks resources that are read immediately when it is rendered. This can cause issues in more complex components, in which a resource is read conditionally only once another resource reaches Some(_) (see example in #4430). This is easy to fix in simple situations but becomes increasingly more difficult as applications become more complex and components are nested. This is especially difficult to deal with in real applications because it represents a race condition between the two resources: if the inner one happens to resolve before the inner one, the bug will not occur; whereas if the inner one is still pending when the outer one has resolved, it will.

This PR is an attempt to improve that behavior by changing the behavior of Suspense to check its children multiple times, until it finds no further resource reads. This adds some performance overhead in exchange for preventing a number of hydration issues that can be hard to track down.

@gbj gbj changed the title fix: track resources in Suspense that are read conditionally behind other resource reads (see #4430) (wip) track resources in Suspense that are read conditionally behind other resource reads (see #4430) Nov 12, 2025
@gbj gbj merged commit 4f3a26c into main Nov 18, 2025
834 of 837 checks passed
@gbj gbj deleted the 4430v2 branch November 18, 2025 02:36
maccesch pushed a commit to maccesch/leptos that referenced this pull request Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants