Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set cache control headers to avoid caching UI #3810

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Apr 18, 2023

Fixes #3806

A PR to get the conversation started.

Root of issue:

When the UI isn't re-rendered in the R process that's serving the Shiny app, we don't have access to global theme information in the server logic. This drives the behavior seen in this issue: the server doesn't know that the UI is expecting BS4+ markup for the nav items and instead emits BS3 markup, and the mismatch results in broken client logic.

Approach:

  • If a theme has been set while creating the UI and the current UI response does not have a caching policy
    • Do not allow caching of the UI

TODO:

  • NEWS entry
  • Test

@jcheng5
Copy link
Member

jcheng5 commented Apr 18, 2023

I think we should always add the cache-busting headers. Without it, Connect and ShinyApps.io configurations will have problems in that the workerId could be a stale value.

Also, here's a little app that, while unrealistic, does break without the cache header (if you navigate away, restart the app, then navigate back). After you've done that, the UI uses a (dynamically generated) id that the server knows nothing about.

library(shiny)

id <- paste0("plot", sample.int(100000, 1))

ui <- fluidPage(
  plotOutput(id)
)

server <- function(input, output, session) {
  output[[id]] <- renderPlot({
    invalidateLater(500)
    plot(rnorm(100))
  })
}

shinyApp(ui, server)

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.

The input$id variable of the navBar does not take into account the inserted panels (insertTab)
3 participants