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

fix: prevent LibraryLayout remount #79

Open
wants to merge 2 commits into
base: jill/fal-3984-fix-autofocus
Choose a base branch
from

Conversation

rpenido
Copy link
Member

@rpenido rpenido commented Jan 16, 2025

No description provided.

@@ -48,7 +50,7 @@ const CollectionInfo = () => {
if (componentPickerMode) {
setCollectionId(collectionId);
} else {
navigateTo({ collectionId });
navigate(`/library/${libraryId}/collection/${collectionId}`);
Copy link
Member Author

@rpenido rpenido Jan 16, 2025

Choose a reason for hiding this comment

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

I changed this to differentiate "Open the collection on the sidebar" from "Open the collection page".

We could add a parameter to navigateTo to handle this. If we go that route, would be nice also to change here:
https://github.com/openedx/frontend-app-authoring/blob/98fbcff842ed760337700e51204e17e940ee7603/src/library-authoring/components/CollectionCard.tsx#L82

I liked the way you did the navigateTo. These hardcoded routes are not nice.

Comment on lines -87 to -88
// now open the previously-selected collection,
? ROUTES.COLLECTION
Copy link
Member Author

Choose a reason for hiding this comment

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

This was causing a redirect to the Collection page on a second click on the collection card.

Comment on lines -29 to -31
/** We need to pass the pathname as key to the LibraryProvider to force a
* re-render when we navigate to a new path or page. */
key={location.pathname}
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes the issue where the LibraryProvider was being remounted when the location.pathname changes.

Copy link
Member

Choose a reason for hiding this comment

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

Why were we trying to force a re-render before?

Copy link
Member Author

Choose a reason for hiding this comment

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

When we navigated to the Collection Page before, the first render still had collectionId = undefined. Remounting the context provider fixed that. It wasn't the best workaround, but it didn't cause many side effects at the time.

@rpenido rpenido force-pushed the rpenido/jill/fal-3984-fix-autofocus/prevent-layout-remount branch from 88c174e to 645e841 Compare January 16, 2025 15:39
Copy link

codecov bot commented Jan 16, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Please upload report for BASE (jill/fal-3984-fix-autofocus@7aaa8f7). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...c/library-authoring/collections/CollectionInfo.tsx 66.66% 1 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##             jill/fal-3984-fix-autofocus      #79   +/-   ##
==============================================================
  Coverage                               ?   93.23%           
==============================================================
  Files                                  ?     1098           
  Lines                                  ?    21704           
  Branches                               ?     4663           
==============================================================
  Hits                                   ?    20236           
  Misses                                 ?     1403           
  Partials                               ?       65           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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