I'm a bit confused about the usage of htmltools::singleton(). In a toy Shiny app, I've created this UI:

ui <- fluidPage(
  singleton(tags$head(tags$script(src = "foo"))),
  tags$head(
    tags$script(src = "foo")
  ),
  tags$script(src = "foo")
)

In the rendered page, all three <script> tags appear; I'd have expected at most two (where the second <script> tag in the <head> is omitted).

This version results in all three tags, too:

ui <- fluidPage(
  tags$head(
    singleton(tags$script(src = "foo")),
    tags$script(src = "foo")
  ),
  tags$script(src = "foo")
)

I've used HTML dependencies before to abstract-away this issue, but here I'd like to use singleton() directly and obviously I'm doing something wrong :-/
Can anyone point me to some working examples of singleton()? (I started to read the unit tests within {htmltools} directly, but I figured to ask the community before heading down that rabbit-hole :-).)

It seems each tag needs to be wrapped in singleton() for this to work as expected:

library(shiny)
library(htmltools)

ui <- fluidPage(
  singleton(tags$p("test")),
  singleton(tags$p("test")),
  singleton(tags$p("test")),
)

server <- function(input, output, session) {}

shinyApp(ui, server)