fix: Wait for download href before fetching (#445)#447
Merged
Conversation
app_download() now waits for the download element's href attribute to be populated before fetching. Previously, if the element wasn't in the DOM yet (e.g., inside an unopened modal) or the href wasn't set by Shiny's output binding, the function would silently download the app's HTML page instead of the intended file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
app_download() now waits internally for the href to be set, so the manual wait_for_js calls before each download are no longer needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verifies that get_download() works correctly when the download button is inside a modal dialog, without needing manual wait_for_js calls. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes an edge case in shinytest2’s download helpers where $get_download() / $expect_download() could fetch the app’s HTML page instead of the intended download when the download element wasn’t yet in the DOM or its href hadn’t been populated (e.g., downloads rendered inside a modal).
Changes:
- Updated the internal download routine to wait until the target element exists and has a non-empty
hrefbefore fetching. - Simplified existing download tests by removing redundant
wait_for_js()guards. - Added a regression test covering a modal-contained download button scenario from #445.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
R/app-driver-expect-download.R |
Adds a chromote_wait_for_condition() wait for non-empty download href, with improved error reporting on timeout. |
tests/testthat/test-app-download.R |
Removes manual JS waits and adds a new regression test for modal-contained downloads. |
NEWS.md |
Documents the behavioral fix for download retrieval and references #445. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
app_download()now waits for the download element'shrefattribute to be populated before fetching, usingchromote_wait_for_condition()with the AppDriver's default timeouthrefwasn't set by Shiny's output binding, the function would silently download the app's HTML page instead of the intended filewait_for_jsguards from existing download testsCloses #445
Test plan
wait_for_jsguardstest-app-download.Rpass🤖 Generated with Claude Code