-
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 all 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,52 @@ | ||
| // 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 | ||
| const oldDefine = window.define; | ||
| window.define = function define(name, deps, callback) { | ||
| if (typeof name !== "string") { | ||
| callback = deps; | ||
| deps = name; | ||
| const script = document.currentScript; | ||
| if (script) { | ||
| name = script.getAttribute("data-requiremodule"); | ||
| if (name) { | ||
| console.info( | ||
| `Changing an anonymous define() call to named define() using '${name}'` | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| return oldDefine.apply(this, [name, deps, callback]); | ||
| }; | ||
| for (var prop in oldDefine) { | ||
| if (oldDefine.hasOwnProperty(prop)) { | ||
| window.define[prop] = oldDefine[prop]; | ||
| } | ||
| } | ||
|
|
||
| // By default, we want UMD loaders to attach themselves to the window. This seems like | ||
| // better/safer default behavior since, the alternative is to have any UMD loader to | ||
| // fail if loaded via a <script> tag. If dependencies actually do want to be | ||
| // define()/require(), they can opt | ||
| window.define.amd = false; | ||
|
|
||
| // In case someone want to restore the old define() function | ||
| window.define.noConflict = function() { | ||
| window.define = oldDefine; | ||
| return this; | ||
| }; | ||
|
|
||
| // 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. | ||
| const oldOnError = window.requirejs.onError; | ||
| window.requirejs.onError = function(err) { | ||
| if (err.message.includes('Mismatched anonymous define()')) { | ||
| err.message = err.message + '\n\nTo avoid this error, consider either: (1) adding a data-requiremodule attribute (with the module name) to the <script> tag containing the anonymous define(), (2) setting define.amd=false, or (3) removing the anonymous define() altogether.'; | ||
| } | ||
|
|
||
| return oldOnError.apply(this, [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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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.