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

No gray screen when app/server disconnects when using waiter #68

Closed
MalditoBarbudo opened this issue Oct 15, 2020 · 2 comments
Closed

Comments

@MalditoBarbudo
Copy link
Contributor

When using waiter and an error occurs triggering the shiny:disconnected event, no gray screen appears. The app is not responsive anymore, but the lack of a visual hint of disconnection can be frustrating until you realize the app is not responding, especially in complex apps.

This can be reproduced clicking the Generate error button in the following example:

library(shiny)
library(waiter)

ui <- fluidPage(
  use_waiter(),
  actionButton("draw", "draw plot"),
  actionButton("gen_error", 'Generate error'),
  plotOutput("plot")
)

server <- function(input, output){
  
  # sets: 
  # input$plot_waiter_shown
  # input$plot_waiter_hidden
  w <- Waiter$new(id = "plot")
  
  dataset <- reactive({
    input$draw
    
    w$show()
    
    on.exit({
      w$hide()
    })
    
    Sys.sleep(3)  
    
    runif(100)
  })
  
  output$plot <- renderPlot(plot(dataset()))
  
  observeEvent(
    input$gen_error,
    {
      stop('no grey, why?')
    }
  )
  
}

shinyApp(ui, server)

I've tracked the error to this code in assets/waiter/custom.js in the latest code in master:

$(document).on('shiny:disconnected', function(event) {
  console.log("seems like a disconnect, hiding waiter"); // this line was added to know when this was triggered
  hide_waiter();
  Shiny.setInputValue("waiter_hidden", true, {priority: 'event'});
});

Following this, in the hide_waiter js function it seems to fail in this step:

  var selector = 'body';

  if(id !== null)
    selector = '#' + id;

  var dom = document.querySelector(selector);

  var overlay = dom.getElementsByClassName("waiter-overlay");
  \\ ... the rest of the function.

The last line fails as the dom is already null, as shown in the chromium console:
> waiter.js:124 Uncaught TypeError: Cannot read property 'getElementsByClassName' of null

I can think on two solutions for this:

  1. Remove the event listener in custom.js. If the app is disconnected anyways, there is no need of removing the waiter.

  2. Add a try-catch to the hide_waiter function, to catch this case and avoid the js error.

@JohnCoene If you can tell me what option you prefer (or have another one on mind), I can make a pull request with the fix ;)

JohnCoene added a commit that referenced this issue Oct 15, 2020
@JohnCoene
Copy link
Owner

Ah! Well spotted thank you. I just removed it for now, might add it back later on :)

Thanks again!

@MalditoBarbudo
Copy link
Contributor Author

Nice!
Thanks for the fast fix!

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

No branches or pull requests

2 participants