Skip to content

Refactor: Precise control over data fetching and task execution#1334

Merged
jcscottiii merged 1 commit intomainfrom
jcscottiii/ui-searches-v6.0.0
Mar 31, 2025
Merged

Refactor: Precise control over data fetching and task execution#1334
jcscottiii merged 1 commit intomainfrom
jcscottiii/ui-searches-v6.0.0

Conversation

@jcscottiii
Copy link
Collaborator

@jcscottiii jcscottiii commented Mar 29, 2025

Background:

This PR refactors data fetching in two components by disabling autoRun for Lit Tasks. An issue was observed in Firefox in PR #1330 where tasks were being triggered multiple times. The previous error handling using TaskNotReadyError and checks for duplicate tasks was insufficient. Lit Task aborts a currently pending task if a new one is triggered. This led to scenarios in Firefox where the initial task could be aborted, and subsequent tasks might return errors, preventing successful data retrieval.

This tries to simplify things by turning off autoRun and leveraging the willUpdate lit lifecycle method to precisely run a task. This also allows us to not have to do checks on the task's arguments within the task itself since we control when the task exactly triggers.

Main changes:

  • OverviewPage: The loadingTask is no longer set to autoRun: true. Instead, it is manually triggered in willUpdate based on changes to relevant properties and bookmark loading status. The TaskNotReadyError and related logic have been removed.
  • webstatus-bookmarks-service:
    • The loadingUserSavedBookmarkByIDTask is no longer set to autoRun: true and is triggered in willUpdate.
    • The task now returns an object containing both the bookmark data and the current search query.

Other changes:

  • webstatus-firebase-auth-service: Updated the type of the user state to User | null | undefined. This is useful for noting whether some data about the user has been loaded successfully or not vs no decision about the user has been made.
  • Removed some redundant tests. Changed some tests to use sinon stubs
  • Added some more coverage too.

Other notes:

  • These tasks don't use the .render() method. They instead control what happens in the onError/onComplete callbacks. I am not saying we need to also change the other tasks that currently use .render() to something like this. Those are currently working. But something to consider if they dependency chain for those tasks become more complicated.

This is a split up of #1330

Background:

This PR refactors data fetching in two components by turning autoRun to false.
I originally observed an issue in Firefox in my original PR (#1330).
The firefox browser was seeing the tasks trigger multiple times and I thought my current handling of TaskNotReadyError and DuplicateErrors/TaskNotReadyError would handle it.
However, in lit task if a task triggers while there's a pending task already running, it would abort the first task. So as a result, sometimes firefox would
not get any information if the original task was aborted and the subsequent tasks were returning one of the DuplicateTaskErrors/TaskNotReadyError causing no more task executions to fully succeed.

This tries to simplify things by turning off autoRun and leveraging the willUpdate lit lifecycle method to precisely run a task. This allows us to not have to do checks on the task's arguments within the task itself since we control when the task exactly triggers.

Main changes:
- **`OverviewPage`:** The `loadingTask` is no longer set to `autoRun: true`. Instead, it is manually triggered in `willUpdate` based on changes to relevant properties and bookmark loading status. The `TaskNotReadyError` and related logic have been removed.
- **`webstatus-bookmarks-service`:**
    - The `loadingUserSavedBookmarkByIDTask` is no longer set to `autoRun: true` and is triggered in `willUpdate`.
    - The task now returns an object containing both the bookmark data and the current search query.

Other changes:
- **`webstatus-firebase-auth-service`:** Updated the type of the `user` state to `User | null | undefined`.
- Removed some redundant tests. Changed some tests to use sinon stubs
- Added some more coverage too.

This is a split up of #1330
@jrobbins
Copy link
Collaborator

some data about the has been loaded

I think you are missing the word "user" in that part of the PR description.

@jcscottiii
Copy link
Collaborator Author

some data about the has been loaded

I think you are missing the word "user" in that part of the PR description.

Thanks!

@jcscottiii jcscottiii added this pull request to the merge queue Mar 31, 2025
Merged via the queue into main with commit 232f174 Mar 31, 2025
6 checks passed
@jcscottiii jcscottiii deleted the jcscottiii/ui-searches-v6.0.0 branch March 31, 2025 17:44
@jrobbins jrobbins mentioned this pull request Apr 2, 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