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

Await component #11936

Merged
merged 4 commits into from
Dec 25, 2024
Merged

Await component #11936

merged 4 commits into from
Dec 25, 2024

Conversation

MrFlashAccount
Copy link
Contributor

@MrFlashAccount MrFlashAccount commented Dec 23, 2024

Pull Request Description

This PR adds an <Await /> component, that allows to trigger Suspense inside the component

const {promise} = useQuery({queryKey: ['data'], queryFn: fetchData})

// Will trigger the suspense within this component
// And once the promise resolves, call the children with the data
// unlike regular approach like `return isLoading ? <Loader /> : <div>{data}</div>`
// it doesn't lead to waterfall of loaders and tell React to keep the tree suspended
// So we always have a single loader, which improves the UX
<Await promise={promise}>
   {(data) => <div>{data}</div>}
</Await>

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

@MrFlashAccount MrFlashAccount self-assigned this Dec 23, 2024
@MrFlashAccount MrFlashAccount added CI: No changelog needed Do not require a changelog entry for this PR. g-dashboard labels Dec 23, 2024
Copy link

github-actions bot commented Dec 23, 2024

🧪 Storybook is successfully deployed!

📊 Dashboard:

Copy link
Contributor

@somebody1234 somebody1234 left a comment

Choose a reason for hiding this comment

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

CR ✅

logic for Await.tsx looks a little scuffed but it's understandable why it's done that way, and if it works it works...

... although i guess having a global WeakMap is a little less cursed, although it will require type assertions

@MrFlashAccount
Copy link
Contributor Author

MrFlashAccount commented Dec 23, 2024

logic for Await.tsx looks a little scuffed but it's understandable why it's done that way, and if it works it works...

What exactly is unclear? Maybe I should provide extra comments to address your questions

I agree on using WeakMaps, it's an alternative solution. If you wish I'll reimplement this using WeakMap, I anyway will add some tests before merging it

@MrFlashAccount MrFlashAccount marked this pull request as ready for review December 23, 2024 12:56
@MrFlashAccount
Copy link
Contributor Author

@Frizi I bumped the @tanstack/vue-query alongside with @tanstack/react-query to get access to promise field in render. Please take a look

@MrFlashAccount MrFlashAccount added the CI: Ready to merge This PR is eligible for automatic merge label Dec 24, 2024
@mergify mergify bot merged commit 0c41e8d into develop Dec 25, 2024
39 checks passed
@mergify mergify bot deleted the wip/sergeigarin/await-component branch December 25, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge g-dashboard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants