Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a note about using suspension #3410

Merged
merged 5 commits into from
Sep 23, 2023

Conversation

its-the-shrimp
Copy link
Contributor

Description

Added a mention of the requirement to store the suspension handle to the Yew Docs on suspense

Fixes #2571

Checklist

  • I have reviewed my own code
  • I have added tests

Copy link
Member

@ranile ranile left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Looks good, just one comment

Also, CI needs to be fixed.

The latter is the one responsible for signaling when to re-render the suspended components, it provides 2 interchangable ways to do so:
1. Calling its [`resume`](https://docs.rs/yew/latest/yew/suspense/struct.SuspensionHandle.html#method.resume) method.
2. Dropping the handle.
If the handle isn't stored for longer than the hook's scope, the suspended components will be constantly re-rendered as often as possible, thus hampering performance.
Copy link
Member

Choose a reason for hiding this comment

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

I would highlight the infinite loop possibility in :::danger.

Danger

The handle must be stored until it's time to render the component. Not doing so could lead to infinite loops

You can word it better for it to go along with the rest of the section

github-actions[bot]
github-actions bot previously approved these changes Sep 23, 2023
@github-actions
Copy link

github-actions bot commented Sep 23, 2023

Visit the preview URL for this PR (updated for commit 0de5e3a):

https://yew-rs--pr3410-fix-suspense-docs-51br2ehe.web.app

(expires Sat, 30 Sep 2023 13:37:52 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

cecton
cecton previously approved these changes Sep 23, 2023
otherwise, the suspended components will enter an infinite re-render loop, thus hampering performance.
In the example above, the suspension handle is preserved by being moved into a closure and passed into `on_load_user_complete`.
When the hypothetical user will be loaded, the closure will be called, thus calling `handle.resume()` and re-rendering the components associated with the suspension context.

Copy link
Member

Choose a reason for hiding this comment

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

:::

An additional pair of colons are needed at the end of the admonitions.

2. Dropping the handle.

:::danger
The suspension handle must be stored until it's time to update components, i.e. with newly received data;
Copy link
Member

Choose a reason for hiding this comment

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

There must be a new line after this. See the link docs about using admonitions with prettier

Copy link
Member

@ranile ranile left a comment

Choose a reason for hiding this comment

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

Thanks, looks good!

@futursolo futursolo merged commit 30e2d54 into yewstack:master Sep 23, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suspension busy polling instead of waiting
4 participants