Repository navigation
Conversation
schloerke
force-pushed
the
schloerke/use-shiny-connected
branch
from
November 9, 2026 21:41
b304c7d to
3a8dd0a
Compare
Shiny fires shiny:connected / disconnected / busy / idle with jQuery's trigger(), which never reaches addEventListener() listeners. So useShinyBusy() never updated in a real browser, and nothing could tell the session had dropped. The lifecycle store now listens through window.jQuery(document).on() when jQuery is present, and tracks a new connected flag exposed as useShinyConnected(). Fixes #328
…y; warn when jQuery is missing The jsdom tests send native events, the very thing that hid #328. The new Playwright test drives a slow output and a session close in a real browser, and fails with native-only listeners. onShinyEvent() now warns when window.Shiny is present but window.jQuery is not, and documents the second-jQuery case it does not handle.
schloerke
force-pushed
the
schloerke/use-shiny-connected
branch
from
November 12, 2026 16:08
3a8dd0a to
e1741f2
Compare
This branch has not been deployed
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.
Fixes posit-dev/shinyreact#328.
Root cause: Shiny fires
shiny:connected,shiny:disconnected,shiny:busy, andshiny:idlewith jQuery'strigger(). That only calls jQuery handlers;document.addEventListener()never sees them. The lifecycle store listened withaddEventListener(), so:useShinyBusy()never updated in a real browser either. Its unit tests passed because they send native events.Changes:
onShinyEvent()helper listens throughwindow.jQuery(document).on()when jQuery is on the page, and falls back toaddEventListener()otherwise. jQuery handlers also get native events, so the jsdom tests still work.shiny:connectedwait both use it.useShinyConnected()hook:falseuntil the socket opens,falseagain on disconnect,trueagain if Shiny reconnects. It seeds fromShiny.shinyapp.isConnected()for late mounts.useShinyInitialized()is unchanged (it staystrue).window.shinyreactand the npm entry, and taught in theshinyreact-build-appskill.Checked by hand in a browser with an R app: "Busy" now shows during a slow request, and stopping the R process flips the hook to
false.