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

Avoid read/write in the event of a cache hit with non-NULL output #42

Merged
merged 5 commits into from
Aug 25, 2020

Conversation

cpsievert
Copy link
Contributor

No description provided.

Copy link
Collaborator

@schloerke schloerke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we'll have to worry about utf8 reading and writing at some point. I wish we had this standardized instead of copying for the nth time.

@cpsievert cpsievert requested a review from wch August 21, 2020 15:22
@wch
Copy link
Collaborator

wch commented Aug 21, 2020

Notes:

  • The return value when output is non-NULL should be consistent -- it shouldn't depend on whether there's a cache hit.
  • Are you sure the change in return value (when output is non-NULL) won't cause breakage in packages that use sass?
  • The docs need to be updated to reflect the change in return value.
  • We should have some tests.
  • We should think about turning on caching by default, at least for shiny.

@wch
Copy link
Collaborator

wch commented Aug 21, 2020

For writing UTF-8, here's what we ended up using in shinytest:
https://github.com/rstudio/shinytest/blob/f8bbbddd6c7c4e2e326b5ef2f738616a458561db/R/utils.R#L174-L177

Note that this does NOT automatically append a trailing \n. The version of the function from Shiny does add a \n if it's not present. The version in shinytest is more faithful to the input, so we should use it. Here's the commit where we changed it in shinytest:
rstudio/shinytest@5ec1208

@cpsievert
Copy link
Contributor Author

cpsievert commented Aug 21, 2020

The return value when output is non-NULL should be consistent -- it shouldn't depend on whether there's a cache hit.

Agreed, whenever output is non-NULL we return(invisible()) now (as we did prior to sass 0.2.0)

Are you sure the change in return value (when output is non-NULL) won't cause breakage in packages that use sass?

I'd be surprised if it does. sass has 4 reverse imports and the return(css) behavior was first introduced in sass 0.2.0 which hit CRAN in mid-March.

The docs need to be updated to reflect the change in return value.

The docs actually say it's return(invisible()):

sass/R/sass.R

Lines 20 to 22 in 0aa3469

#' @return If \code{output = NULL}, the function returns a string value
#' of the compiled CSS. If the output path is specified, the compiled
#' CSS is written to that file and \code{invisible()} is returned.

When I changed it to return(css) when we implemented sass_layer(), I had forgot to update the docs (9d77894)

We should have some tests.

Just FYI, there are quite a bit of caching tests, but I'll look into adding a few more specifically for this logic

We should think about turning on caching by default, at least for shiny.

Ok, in that case, we'll have to find some way account for the bootstraplib version (bootstraplib themes include @imports of scss files from the installed packaged directory)

R/sass.R Show resolved Hide resolved
@cpsievert cpsievert merged commit 7e4aa87 into master Aug 25, 2020
@cpsievert cpsievert deleted the carson/feature/avoid-io branch August 25, 2020 19:14
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.

3 participants