Skip to content

fix: require an app onBookmarked() callback; explain the missing Bootstrap modal - #334

Open
schloerke wants to merge 1 commit into
schloerke/use-shiny-connectedfrom
schloerke/bookmark-default
Open

schloerke wants to merge 1 commit into
schloerke/use-shiny-connectedfrom
schloerke/bookmark-default

Conversation

@schloerke

@schloerke schloerke commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes posit-dev/shinyreact#326.

When an app registers no onBookmarked() / on_bookmarked() callback, Shiny shows the bookmark URL in a Bootstrap modal. page_react() loads no Bootstrap, so session$doBookmark() / session.bookmark() threw $(...).modal is not a function.

shinyreact does not register a default callback. To step aside when the app registers its own, it would have to read Shiny's private callback list, and Shiny registers no function of its own to recognize: its modal is a fallback branch inside doBookmark().

Instead:

  • Apps register their own callback. The R vignette, the build-app skill, and the 10-bookmarking example now do:
    • R: onBookmarked(function(url) updateQueryString(url))
    • Python: session.bookmark.on_bookmarked(session.bookmark.update_query_string)
  • A clear console error when they don't. At load, the bundle fills an empty jQuery.fn.modal with a function that logs a [shinyreact] error naming that fix. This covers every Shiny modal (showModal() / modal_show() too). It never replaces an existing modal, so Bootstrap already on the page wins, and a Bootstrap loaded later overwrites it. The modal's HTML is still dropped, unstyled, at the end of <body>.

Playwright tests cover both paths: the documented callback rewrites the URL, and with no callback the [shinyreact] error is logged and modal is not a function is not thrown.

@schloerke
schloerke added this pull request to stack #335 November 9, 2026 18:21
@schloerke
schloerke force-pushed the schloerke/bookmark-default branch 2 times, most recently from 3a669dd to fddbe22 Compare November 12, 2026 16:08
…strap modal

With no onBookmarked() callback, Shiny shows the bookmark URL in a Bootstrap
modal, and page_react() loads no Bootstrap, so session$doBookmark() /
session.bookmark() threw "$(...).modal is not a function".

shinyreact does not register a default callback: telling an app's callback
from Shiny's fallback needs Shiny's private callback list. Instead, the docs,
skill, and the 10-bookmarking example register
onBookmarked(function(url) updateQueryString(url)) /
session.bookmark.on_bookmarked(session.bookmark.update_query_string), and the
bundle fills an empty jQuery.fn.modal so any Shiny modal on a Bootstrap-free
page logs a [shinyreact] console error naming that fix.

Fixes #326
@schloerke
schloerke force-pushed the schloerke/bookmark-default branch from fddbe22 to 7922d93 Compare November 12, 2026 21:13
@schloerke schloerke changed the title fix: write the bookmark URL to the address bar instead of a Bootstrap modal fix: require an app onBookmarked() callback; explain the missing Bootstrap modal Nov 12, 2026

This branch has not been deployed

No deployments
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.

Default bookmark URL modal fails on page_react() pages ($(...).modal is not a function)

1 participant