Skip to content

11327/feature/make follow buttons asynchronous#11350

Merged
jimchamp merged 7 commits intointernetarchive:masterfrom
taearls:11327/feature/make-follow-buttons-asynchronous
Nov 4, 2025
Merged

11327/feature/make follow buttons asynchronous#11350
jimchamp merged 7 commits intointernetarchive:masterfrom
taearls:11327/feature/make-follow-buttons-asynchronous

Conversation

@taearls
Copy link
Copy Markdown
Contributor

@taearls taearls commented Oct 14, 2025

Closes #11327

feature: makes follow buttons work asynchronously

Technical

Testing

I followed the steps here #11327 (comment)

Screenshot

here is the follow button on the /people/openlibrary profile page

openlibrary follow button demo

Stakeholders

@jimchamp

Copy link
Copy Markdown
Collaborator

@jimchamp jimchamp left a comment

Choose a reason for hiding this comment

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

Thanks @taearls! Looks like this is almost ready, but it's not working.

following.js is never imported in index.js, so the initialization function is never called on profile pages. I've left a suggested code change that should fix this.

Be sure to use your browser's dev tools when testing this. Specifically, open the network tab and ensure that the async request is actually occurring.

Comment on lines +555 to +557
if (followForms.length) {
module.initAsyncFollowing(followForms);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The initAsyncFollowing function is in the following.js file. This block of code imports book-page-lists.js, which does not export this function.

As a result, I'm seeing Possible Unhandled Promise Rejection: TypeError: e.initAsyncFollowing is not a function in the console when I visit a profile page containing a "Follow" button.

Please move the followForms declaration below the if (listSection) block, and add similar to the following (untested) code:

if (followForms.length) {
    import(/* webpackChunkName: "following" */ './following')
        .then(module => {
            module.initAsyncFollowing(followForms)
        })
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh woops I think I had it in both by mistake and removed the wrong one. I'll fix that!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe I have fixed it. There are a lot of info logs but no warning anymore about the Possible Unhandled Promise Rejection.

Screenshot 2025-10-14 at 2 59 43 PM

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't look like it will work. Does the entire page reload when the button is pressed? We do not want that to happen.

In order to give the issue's original assignee a chance to share their work, I'm not going to review or test your changes until tomorrow. You may also want to wait and see if they open a PR before making any more changes to this -- it's up to you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's fair. I appreciate your suggestions and patience.

I decided to take a quick look because I was curious. In hindsight, I think I misunderstood when you had suggested to place the new following code below the list section code. I pushed a small change to make the lazy-loaded initAsyncFollowing script separate from the lazy-loaded initListSection script. I think it worked the same way before, but to me it made sense to separate concerns.

From what I can tell, it doesn't appear that the page reloads. If it were reloading the page I would expect document request types for the openlibrary html, and that the page content would flash when I clicked the Follow / Unfollow button. I just see that there's a fetch request with no content in the response.

Comment on lines -47 to -49

const followForms = listSection.querySelectorAll('.follow-form');
initAsyncFollowing(followForms)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This needs to be here. On book pages we lazy-load the lists section. This hydrates the follow buttons after they are attached to the DOM.

With this code removed, a click on a book page "Follow" button will take the patron to a new page, which is not what we want.

It probably goes without saying, but you'll have to import initAsyncFollowing in this file for this to work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@taearls taearls requested a review from jimchamp October 18, 2025 09:12
Copy link
Copy Markdown
Collaborator

@jimchamp jimchamp left a comment

Choose a reason for hiding this comment

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

Sorry for the massive delay... This is working as expected. Thanks again, @taearls!

@jimchamp jimchamp merged commit 6d2c117 into internetarchive:master Nov 4, 2025
4 checks passed
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.

Make all follow buttons work asynchronously

2 participants