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

Fix #2348, #2329, #1817: bugs triggered by networkD3 sankey plot #2361

Merged
merged 5 commits into from
Mar 27, 2019

Conversation

alandipert
Copy link
Contributor

This PR supersedes #2359 as it includes some new infrastructure for managing patches to bootstrap-datepicker

Cause and fix

  • All of these were caused by the presence of multiple body tags on the page, which happened because networkD3's sankey plot generates SVGs containing body tags via SVG's foreignObject tag
  • In various places, the 'body' jQuery selector string is used under the assumption there is only one body tag on the page. The presence of multiple body tags breaks reliant code in strange ways.
  • The fix in all cases was to make the selector more specific: 'body:first' or document.body do the job.

Issues that were fixed

Further context

Note that this has troubled networkD3 users for a long time: christophergandrud/networkD3#214

The way Shiny behaves, that this PR addresses, is not strictly "wrong" — it should be safe to assume that in a given HTML page, only one body will appear. However, the existence of the problem is proof of how confusing foreignObject is (the SVG spec example for foreignObject demonstrates embedding body in an SVG!), and so it seems like a good policy for Shiny to do the robust (if technically unnecessary) thing.

New patch infrastructure

This PR also includes two new scripts, tools/updateBootstrapDatepicker.R and tools/applyDatepickerPatches.R, that can be used together to manage our own changes to the bootstrap-datepicker 3rd party library. A section was added to tools/README.md documenting their use.

In order to switch to this new method of applying patches, bootstrap-datepicker version 1.6.4 was re-imported, and a previously committed change was converted to a .patch and re-applied using the new tools.

@alandipert
Copy link
Contributor Author

alandipert commented Mar 27, 2019

@wch One problem with this approach that we may want to rectify is, if the bootstrap-datepicker repo disappears, we don't have a way to revert to a "clean import", since the version in git is the one we've patched.

We might consider adding the bootstrap-datepicker release zip file to our repo as part of the import process (for 1.6.4 it's 97k). What do you think?

Update

Nevermind, I realized that if we ever needed to do this we could git apply the patches in reverse order and with the --reverse flag.

Copy link
Collaborator

@wch wch left a comment

Choose a reason for hiding this comment

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

Looks good, other than a few small things.

tools/README.md Outdated

After updating, our patches to `bootstrap-datepicker` must be applied using the script `applyDatepickerPatches.R`

After updating and applying patches, `yarn grunt` should be run per the instructions above.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might want to mention why this is necessary (to generate the minified JS file).

tools/README.md Outdated

1. Make any necessary changes to files in `inst/www/shared/datepicker`
1. **Do not commit your changes.**
1. Instead, create a patch with a command like `git diff > tools/datepicker-patches/012-a-description.patch`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mention that the patches are applied in numeric order.

NEWS.md Show resolved Hide resolved
unzip(
dest_file,
files = c(
"js/bootstrap-datepicker.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Needs locales subdir also.

@alandipert alandipert force-pushed the fix-svg-foreignobject branch 3 times, most recently from 99715d6 to a13dd73 Compare March 27, 2019 18:32
* All of these were caused by the presence of multiple body tags on the
page, which happened because networkD3's sankey plot generates SVGs
containing body tags via SVG's foreignObject tag
* In various places, the 'body' jQuery selector string is used under the
assumption there is only one 'body' tag on the page. The presence of
multiple 'body' tags breaks reliant code in strange ways.
* The fix was to use document.body or 'body:first' instead of 'body'.
@alandipert alandipert force-pushed the fix-svg-foreignobject branch from a13dd73 to 908d635 Compare March 27, 2019 18:36
@wch wch merged commit 92019b5 into rc-v1.3.0 Mar 27, 2019
@wch wch deleted the fix-svg-foreignobject branch March 27, 2019 18:40
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.

2 participants