fix: fire shiny:outputinvalidated for outputs bound after invalidation#4373
Open
fix: fire shiny:outputinvalidated for outputs bound after invalidation#4373
Conversation
70090ef to
a1c4bb9
Compare
a1c4bb9 to
75a6fe1
Compare
#2797) When an output is invalidated before it's in the DOM (e.g., inside a closed modal), the shiny:outputinvalidated event was never fired. The progress state machine already tracks this — the Invalidated state means "this output was invalidated while not bound." Adds isInvalidated() to OutputProgressReporter and uses it in bindOutputs() to fire the event when an output in the Invalidated state is first bound. This is intentionally separate from the isRecalculating() check that drives showProgress(), since isRecalculating() also includes the Initial state (every output on first page load) where firing the invalidated event would be incorrect.
Matches the event payload shape from progressHandlers.binding in shinyapp.ts, where event.binding is an OutputBindingAdapter.
…ordering Matches the ordering in progressHandlers.binding (shinyapp.ts), where the event fires before _updateProgress() applies showProgress.
Covers isRecalculating, isInvalidated, takeChanges, full lifecycle transitions (value, error, cancel, persistent paths), and invalid transition errors. 33 tests total.
52d91ad to
f626f2c
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes missing dispatch of the shiny:outputinvalidated event for outputs that were invalidated while not yet present in the DOM (e.g., inside a closed modal), complementing the progress state machine introduced in #4039 and closing #2797.
Changes:
- Add
OutputProgressReporter.isInvalidated()and expose it through the bind context. - Fire
shiny:outputinvalidatedduring output binding when the output is already in theInvalidatedstate. - Add unit tests covering
OutputProgressReporterstate transitions and newisInvalidated()behavior.
Reviewed changes
Copilot reviewed 5 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| srcts/src/shiny/outputProgress.ts | Adds isInvalidated() to the output progress state machine. |
| srcts/src/shiny/bind.ts | Uses outputIsInvalidated() during output binding to trigger shiny:outputinvalidated. |
| srcts/src/shiny/index.ts | Threads outputIsInvalidated() into the bind context. |
| srcts/src/shiny/tests/outputProgress.test.ts | Adds state machine unit tests, including isInvalidated(). |
| srcts/types/src/shiny/outputProgress.d.ts | Updates typings for the new isInvalidated() API. |
| srcts/types/src/shiny/bind.d.ts | Updates typings for the new bind context callback. |
| inst/www/shared/shiny.js | Built output reflecting the TS changes. |
| inst/www/shared/shiny.min.js | Minified built output reflecting the TS changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+313
to
+317
| void test("recalculating from Value throws", () => { | ||
| const r = new OutputProgressReporter(); | ||
| runFullCycle(r, "x", "value"); | ||
| assert.throws(() => r.updateStateFromMessage(recalculated("x"))); | ||
| }); |
Comment on lines
+359
to
+366
| if (outputIsInvalidated(id)) { | ||
| $el.trigger({ | ||
| type: "shiny:outputinvalidated", | ||
| // @ts-expect-error; Can not remove info on a established, malformed Event object | ||
| binding: bindingAdapter, | ||
| name: id, | ||
| }); | ||
| } |
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.
Closes #2797
Summary
shiny:outputinvalidatedjQuery event was never fired. PR Improve/fix output progress reporting #4039 introduced a state machine that correctly appliesshowProgress(true)when such outputs are later bound, but the corresponding event dispatch was missing. This adds it.isInvalidated()toOutputProgressReporterand uses it inbindOutputs()to fire the event only when an output in theInvalidatedstate is first bound. This is intentionally a separate check fromisRecalculating()(which drivesshowProgress), becauseisRecalculating()includes theInitialstate — firingshiny:outputinvalidatedfor every output on first page load would be incorrect.Context
Issue #2797 reported three problems with outputs inside modals:
shiny:outputinvalidatednever firesshiny:recalculating/shiny:recalculatedfire at the wrong time.recalculatingCSS class is never addedProblems 2 and 3 were fixed by #4039. This PR fixes problem 1, completing the fix for #2797.
Manual testing app
Steps:
x()while the modal is closedBefore fix: The event log shows
outputinvalidated: mainOutput(step 2) but neveroutputinvalidated: insideModal.After fix: The event log shows
outputinvalidated: insideModalwhen the modal reopens (step 3).Note: use
pkgload::load_all(".")to test the development version rather than the installed package.Test plan
OutputProgressReporterstate machine (33 tests coveringisRecalculating,isInvalidated, state transitions,takeChanges, and invalid transitions)main, PASS on branch)shiny:outputinvalidateddoes NOT fire for outputs on initial page load (onlyshowProgress/.recalculatingclass should be applied in that case)