Skip to content

fix: tolerate NULL state$values in onBookmark callback - #287

Merged
cpsievert merged 1 commit into
mainfrom
fix/bookmark-null-values
Sep 5, 2026
Merged

fix: tolerate NULL state$values in onBookmark callback#287
cpsievert merged 1 commit into
mainfrom
fix/bookmark-null-values

Conversation

@cpsievert

Copy link
Copy Markdown
Contributor

Problem

With chat history enabled, submitting a prompt can produce:

Warning: Error in utils::modifyList: is.list(x) is not TRUE
  ...
  131: state$onSave
   99: session$doBookmark
   98: self$on_response_saved
   97: controller$on_response

shinychat's history save triggers a Shiny bookmark (session$doBookmark()) after each response. In that context the onBookmark callback's state$values can be NULL, but utils::modifyList(NULL, ...) fails because modifyList() requires a list as its first argument.

Repro

# inside mod_server, the onBookmark callback does:
shiny::onBookmark(function(state) {
  state$values <- utils::modifyList(state$values, build_state_snapshot())
})

# when history triggers the bookmark, this can arrive as:
state$values <- NULL
utils::modifyList(NULL, list(querychat_tables = ...))
# Error: is.list(x) is not TRUE

Observed in querychat_app(penguins) with default (file-based) history after submitting a prompt.

Fix

Coalesce state$values to an empty list before merging the state snapshot:

state$values <- utils::modifyList(state$values %||% list(), build_state_snapshot())

Includes a regression test that drives mod_server via testServer and invokes the captured onBookmark callback with state$values <- NULL.

When shinychat's history save triggers the bookmark, state$values can be
NULL, and utils::modifyList() requires a list. Coalesce to an empty list
before merging the querychat state snapshot.
@cpsievert
cpsievert force-pushed the fix/bookmark-null-values branch from f1cf0ff to c6ebd17 Compare September 5, 2026 01:13
@cpsievert
cpsievert merged commit 4754b98 into main Sep 5, 2026
10 checks passed
@cpsievert
cpsievert deleted the fix/bookmark-null-values branch September 5, 2026 01:14
@github-actions
github-actions Bot restored the fix/bookmark-null-values branch September 5, 2026 01:15
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.

1 participant