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

GridModel.selectFirstAsync should respect intentionally not-mounted grid component #3633

Open
PeteDarinzo opened this issue Apr 18, 2024 · 1 comment
Labels

Comments

@PeteDarinzo
Copy link
Contributor

PeteDarinzo commented Apr 18, 2024

Issue Summary: Attempting the select the first row in an intentionally not-mounted grid will cause a three second mask. A grid may be intentionally not-mounted if something is chosen to render in its place if its store is empty, for example a placeholder component.

When calling selectFirstAsync on a GridModel, it first checks its isReady property, and waits for it to become true if it isn't already. The GridModel's isReady is a trampoline from its AgGridModel's property, which is evaluated based on whether the grid component is fully initialized and mounted.

The awaiting occurs when GridModel's selectFirstAsync calls its whenReadyAsync method, which waits for isReady true, for a default of three seconds. If after the timeout, the grid is still not ready, selectFirstAsync simply returns. The primary purpose of waiting for isReady is to allow a grid component time to mount, if it wasn't already.

In some cases, an app may choose to only mount a grid if it has rows, and display another component, e.g. a placeholder instead. If the app is selecting the first row after loading, then the following will happen after loading the GridModel with no records:

  1. Load the GridModel with no rows.
  2. The grid is not rendered, and another component displayed instead.
  3. Attempt to select the first row in the grid.
  4. Since the grid is not mounted, isReady never turns true.
  5. A three second (default) mask is displayed while the GridModel waits for the grid to mount (which never happens), after which it returns.

This results in what seems like a performance issue when loading an empty grid. A quick workaround is to return in the app's doLoadAsync method after loading the GridModel, and before attempting to select the first row, if no records where loaded. A more robust fix is for selectFirstAsync to know whether the grid component is intentionally not-mounted, return if so, and only await isReady otherwise.

@amcclain amcclain changed the title GridModel selectFirstAsync should respect intentionally not-mounted grid component 1GridModel.selectFirstAsync` should respect intentionally not-mounted grid component Apr 22, 2024
@amcclain amcclain changed the title 1GridModel.selectFirstAsync` should respect intentionally not-mounted grid component GridModel.selectFirstAsync should respect intentionally not-mounted grid component Apr 22, 2024
@amcclain
Copy link
Member

In your app code, could you simply not await the call to selectFirstAsync? Or (for when there are any rows), do you need to ensure that the first row has been fully selected before that method completes?

That said, it does seem like GridModel could do check at the top of selectFirstAsync and return immediately if its store is empty. I can't think of any reason why that would be a bad idea - or to put it another way, I can't think of any case where GridModel would have a row to select if it's store is empty.

I'd suggest a quick look at any other methods there that await this.whenReadyAsync() to see if the same early-out should be applied elsewhere for consistency.

@amcclain amcclain added the grid label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants