-
Notifications
You must be signed in to change notification settings - Fork 114
Depend on require.js to make it usable with other UMD HTMLDependency()s #160
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9389f9a
Close #120: Introduce require.js as an initial 'core' dependency with…
cpsievert 91daabb
Trigger a rebind when requirejs is done loading a module
cpsievert 1418b5c
No need to require.config() jquery-ui's path since jquery-ui.min.js a…
cpsievert 449e787
Remove requirejs load event handling in favor of shiny's wip bugfix f…
cpsievert a607092
update shiny.js
cpsievert c775ab0
Load jQuery and Bootstrap before requirejs so they get attached to th…
cpsievert 287e079
Add some more information to anonymous define() errors and bundle the…
cpsievert 8e97e4f
Upgrade jQuery and only include draggable interactions
cpsievert f12e45f
Revert "Upgrade jQuery and only include draggable interactions"
cpsievert 02855f8
Set define.amd=false
cpsievert 3d1bc36
Revert inclusion of shiny.js changes; improve comment
cpsievert c83af1e
Bring back define() shim
cpsievert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Make Shiny's global dependencies require()-able. A non-trivial amount of Shiny's | ||
// legacy JS code depends on these globals, but it seems reasonable to think other | ||
// downstream code want to require('jquery') (panel_absolute() does that via | ||
// require('jquery-ui')). | ||
define('jquery', [], function() { return jQuery }); | ||
define('bootstrap', [], function() { return bootstrap }); | ||
|
||
// Since HTMLDependency()s are designed to be loaded via a <script> tag, we do our best | ||
// to avoid anonymous define() calls (which will error out in a script tag) | ||
// https://requirejs.org/docs/errors.html#mismatch | ||
// | ||
// One way to approach this is to lean on the data-requiremodule attribute, which | ||
// requirejs happens to set when it loads scripts in the browser | ||
// https://github.com/requirejs/requirejs/blob/898ff9/require.js#L1897-L1902 | ||
const oldDefine = window.define; | ||
window.define = function define(name, deps, callback) { | ||
if (typeof name !== 'string') { | ||
callback = deps; | ||
deps = name; | ||
name = document.currentScript.getAttribute('data-requiremodule') | ||
} | ||
return oldDefine.apply(this, [name, deps, callback]); | ||
} | ||
for(var prop in oldDefine) { | ||
if (oldDefine.hasOwnProperty(prop)) { | ||
window.define[prop] = oldDefine[prop]; | ||
} | ||
} | ||
|
||
// Users can still encounter this anonymous define() error, and we've actually | ||
// encountered this in shiny-server-client.js because we were inlining an internal | ||
// dependency that contained an anonymous define() | ||
// https://github.com/rstudio/shiny-server-client/blob/5ee5aac/dist/shiny-server-client.js#L4271-L4272). | ||
// In this case, it doesn't seem like there is anything we can do to help the situation | ||
// other than to add some more context to the error. | ||
window.requirejs.onError = function(err) { | ||
if (err.message.includes('Mismatched anonymous define()')) { | ||
err.message = err.message + '\n\nConsider either adding a data-requiremodule attribute (with the module name) to the <script> tag containing the anonymous define() or removing the anonymous define() altogether.'; | ||
} | ||
throw err; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.