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

[noTicket][risk=no]Fix workspace showing up for wrong section #8762

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NehaBroad
Copy link
Collaborator

@NehaBroad NehaBroad commented Sep 3, 2024

This issue is caused by a race condition that occurs when a user navigates from one category to another before the initial category has finished loading on page load.

An alternative solution is to fetch all featured workspaces during the initial page load and then filter them based on the selected category. However, the downside of this approach is that users won't see the latest workspaces unless the page is fully reloaded.


PR checklist

  • I have included an issue ID or "no ticket" in the PR title as outlined in CONTRIBUTING.md.
  • I have included a risk tag of the form [risk=no|low|moderate|severe] in the PR title as outlined in CONTRIBUTING.md.
  • I have manually tested this change and my testing process is described above.
  • This change includes appropriate automated tests, and I have documented any behavior that cannot be tested with code.
  • I have added explanatory comments where the logic is not obvious.
  • One or more of the following is true:
    • This change is intended to complete a JIRA story, so I have checked that all AC are met for that story.
    • This change fixes a bug, so I have ensured the steps to reproduce are in the Jira ticket or provided above.
    • This change impacts deployment safety (e.g. removing/altering APIs which are in use), so I have documented the impacts in the description.
    • This change includes a new feature flag, so I have created and linked new JIRA tickets to (a) turn on the feature flag and (b) remove it later.
    • This change modifies the UI, so I have taken screenshots or recordings of the new behavior and notified the PO and UX designer in Slack.
    • This change modifies API behavior, so I have run the relevant E2E tests locally because API changes are not covered by our PR checks.
    • None of the above apply to this change.

@@ -193,6 +193,7 @@ export const FeaturedWorkspaces = (props) => {
);
setWorkspaceList(
workspacesReceived.items
.filter((fw) => fw.workspace.featuredCategory === currentTab.category)
Copy link
Collaborator

@evrii evrii Sep 3, 2024

Choose a reason for hiding this comment

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

I'm curious if this will work, because it does not seem to remove the race condition.

I believe that if you have two calls to two different featured category and the first call finishes after the second, you will end up in a weird spot. You will end up with workspacesReceived reflecting the results from the first call but currentTab.category reflecting the category of the second call. In this case, no results will be shown, because there shouldn't be any workspaces in the first call of the second category.

I wonder if you could rewrite this to something like this:

const [workspaceRequestAbortController, setWorkspaceRequestAbortController] =
    useState<AbortController|null>(null);
...
const controller = new AbortController();
const signal = controller.signal;
setWorkspaceRequestAbortController(controller);
featuredWorkspaceApi().getFeaturedWorkspacesByCategory(currentTab.category, { signal })
  .then(workspacesReceived => {
          setWorkspaceList(
        workspacesReceived.items
          .sort((a, b) => a.workspace.name.localeCompare(b.workspace.name))
          .map((w) => new WorkspacePermissions(w))
      );
  })
  
...
  
useEffect(() => {
    workspaceRequestAbortController.abort()
    props.hideSpinner();
    getAllPublishedWorkspaces();
  }, [currentTab]);

Copy link
Collaborator

@jmthibault79 jmthibault79 left a comment

Choose a reason for hiding this comment

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

This does not solve the problem. I still see the bug.

I like the "alternative" you mention. Let's try that.

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.

3 participants