Skip to content

Fix use_query and use_prepared_query stalling issue#105

Open
Madoshakalaka wants to merge 10 commits intobounce-rs:masterfrom
Madoshakalaka:use_query-stall-fix-2
Open

Fix use_query and use_prepared_query stalling issue#105
Madoshakalaka wants to merge 10 commits intobounce-rs:masterfrom
Madoshakalaka:use_query-stall-fix-2

Conversation

@Madoshakalaka
Copy link
Copy Markdown
Contributor

@Madoshakalaka Madoshakalaka commented Jul 10, 2025

Description

#104 was an ugly fix with an extra yew_hooks dependency, I think this PR fixes #102 and #99 properly.

I have tested bounce before and after the fix on two minimal repos:

https://github.com/Madoshakalaka/use-query-stalls
and
https://github.com/Madoshakalaka/use-prepared-query-stall
(a SSR setup with axum)

I made sure

  1. the stalling behavior is fixed.
  2. no duplicate requests on new input
  3. response caching works on seen inputs

Checklist

  • I have self-reviewed and tested this pull request to my best ability.
  • I have added tests for my changes.
  • I have updated docs to reflect any new features / changes in this pull request.
  • I have added my changes to CHANGELOG.md.

let run_query = run_query.clone();

if value_state.value.is_none() {
run_query(RunQueryInput {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I still don’t think this is the correct solution.

This piece of code is running side effects without a use_effect clause.

This is meant to be run exactly once.

Function components should not modify states at the rendering stage where it has no control over when or how many times the renderer will trigger this piece of code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about now, I restructured both use_query and use_prepared_query to follow Yew's
use_future_with pattern. And added some e2e tests to assert the number of fetches.

# Conflicts:
#	.github/workflows/everything.yml
#	CHANGELOG.md
Restructures use_query and use_prepared_query to follow Yew's
use_future_with pattern: query initiation is now integral to
producing the Suspension value via Suspension::from_future,
rather than being a bare side effect in the render body.

Adds browser-based e2e tests using fantoccini/geckodriver that verify:
- use_query and use_prepared_query do not stall on input change
- query results are cached for seen inputs
- no duplicate requests are made
The e2e crate depends on tokio/mio which cannot compile for wasm32.
Excluding it from the workspace prevents cargo make tests from
trying to build it for the wasm target.
# Conflicts:
#	examples/queries-ssr/src/lib.rs
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.

use_query seems to stall forever without running the query

2 participants