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

Global Namespace Pollution #241

Closed
GordonSmith opened this issue Mar 31, 2020 · 6 comments
Closed

Global Namespace Pollution #241

GordonSmith opened this issue Mar 31, 2020 · 6 comments

Comments

@GordonSmith
Copy link

I suspect this is being pulled in by d3-require, but window.define gets overwritten even if it existed prior to loading this library: https://github.com/d3/d3-require/blob/master/src/index.js#L88

@mbostock
Copy link
Member

That’s correct. Unfortunately this is not something we can fix because it’s how AMD works: the global define is needed so that when require’d modules load asynchronously, they can register themselves with the AMD loader.

@mbostock
Copy link
Member

Duplicate of d3/d3-require#33.

@GordonSmith
Copy link
Author

@mbostock This is bit of a shame as it prevents the embedding of download notebooks in third party web sites...

@mbostock
Copy link
Member

@GordonSmith It only applies if you call require, in which case you’ll need the global define or the notebook will be broken, anyway. If you don’t call require, the global define won’t be set.

@GordonSmith
Copy link
Author

Unfortunately that is any notebook which contains some markdown as the stdlib requires the markdown js library,..

IOW embedding any notebook which contains markdown will overwrite the previously declared global define, potentially causing pain for the hosting website.

To be fair AMD require implementations have been battling this issue forever...

@mootari
Copy link
Member

mootari commented Apr 1, 2020

@GordonSmith I recommend moving the discussion to https://talk.observablehq.com/, where others with practical experience wrt embedding might be able to assist you.

As an aside, you could try to define get/set callbacks for window.define (here are some examples for scope wrapping and object proxying).

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

No branches or pull requests

3 participants