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

Debounce page refreshes triggered via Turbo streams #1099

Merged

Conversation

brunoprietog
Copy link
Contributor

Fixes #1093

Copy link
Contributor

@edwinv edwinv left a comment

Choose a reason for hiding this comment

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

Great work! A already started adding debounce as well, but this PR makes my work
superfluous. Hopefully my feedback helps to craft the best solution.

src/core/session.js Outdated Show resolved Hide resolved
src/tests/functional/page_refresh_stream_action_tests.js Outdated Show resolved Hide resolved
src/tests/helpers/page.js Outdated Show resolved Hide resolved
@brunoprietog brunoprietog force-pushed the debounce-stream-refreshes branch 2 times, most recently from e237023 to 624b9c6 Compare December 4, 2023 12:03
Copy link
Contributor

@edwinv edwinv left a comment

Choose a reason for hiding this comment

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

Much more readable now! 🙏 Other than a possible extra test case, I don't have feedback anymore.

src/core/session.js Outdated Show resolved Hide resolved
Copy link
Member

@jorgemanrubia jorgemanrubia left a comment

Choose a reason for hiding this comment

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

@brunoprietog Thanks for working on this. I added some minor comments.

src/core/session.js Outdated Show resolved Hide resolved
src/tests/functional/page_refresh_stream_action_tests.js Outdated Show resolved Hide resolved
@brunoprietog
Copy link
Contributor Author

@jorgemanrubia I've added the Turbo.session.pageRefreshDebouncePeriod setting but I had to change the implementation slightly, so that changing the value changes the debounce delay again. Can you think of a more elegant way to do this or is it ok?

Copy link
Member

@jorgemanrubia jorgemanrubia left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @brunoprietog. I added a few more comments, but good call noticing we need to account for the change of the property when scheduling the debounce logic.

@@ -177,7 +177,7 @@ test("test action=refresh", async () => {
const element = createStreamElement("refresh")
subject.append(element)

await nextBeat()
await sleep(250)
Copy link
Member

Choose a reason for hiding this comment

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

Could we use nextPageRefresh instead of the remaining sleep(250)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That helper uses Playwright and we don't have access to it here, that's why I haven't changed it. But you're right that it doesn't read well.

src/core/session.js Outdated Show resolved Hide resolved
src/core/session.js Show resolved Hide resolved
Fix Turbo 8 refresh debounce in frontend hotwired#1093
Copy link
Member

@jorgemanrubia jorgemanrubia left a comment

Choose a reason for hiding this comment

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

Thanks @brunoprietog

@jorgemanrubia jorgemanrubia merged commit 6fc2f38 into hotwired:main Jan 7, 2024
1 check passed
@brunoprietog brunoprietog deleted the debounce-stream-refreshes branch January 7, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Turbo 8 refresh debounce in frontend
4 participants