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 client on pages that define a variable called global #3385

Merged
merged 1 commit into from
May 30, 2016

Conversation

robertknight
Copy link
Member

Modules which assume the existence of a global variable called "global"
(which exists in Node) are wrapped by Browserify during the build which
normally results in "global" being aliased to "self" or "window" in a
browser environment.

If code on the page into which H is loaded defines a global variable
called "global" however, that gets used instead and this can break such
modules. In the case of https://www.civilsprep.com, "global" is a
reference to a DOM node for example.

This commit fixes the issue by only aliasing "global" (as seen by the
module using it) to either "window" or "self" and not to any existing
variable called "global".

Fixes #2723

Modules which assume the existence of a global variable called "global"
(which exists in Node) are wrapped by Browserify during the build which
normally results in "global" being aliased to "self" or "window" in a
browser environment.

If code on the page into which H is loaded defines a global variable
called "global" however, that gets used instead and this can break such
modules. In the case of https://www.civilsprep.com, "global" is a
reference to a DOM node for example.

This commit fixes the issue by only aliasing "global" (as seen by the
module using it) to either "window" or "self" and not to any existing
variable called "global".

Fixes #2723
@robertknight
Copy link
Member Author

@codecov-io
Copy link

codecov-io commented May 30, 2016

Current coverage is 74.03%

Merging #3385 into master will not change coverage

  1. 3 files (not in diff) in h were modified. more
    • Misses -3
    • Partials +3
@@             master      #3385   diff @@
==========================================
  Files           131        131          
  Lines          4732       4732          
  Methods           0          0          
  Messages          0          0          
  Branches        559        559          
==========================================
  Hits           3503       3503          
+ Misses         1152       1149     -3   
- Partials         77         80     +3   

Sunburst

Powered by Codecov. Last updated by 161710a...28a8c70

@chdorner
Copy link
Contributor

LGTM. Tested it on the page and injecting the client works as expected now 👍

@chdorner chdorner merged commit 7f4b1d7 into master May 30, 2016
@chdorner chdorner deleted the gh2723-fix-client-on-pages-that-define-global branch May 30, 2016 13:13
robertknight added a commit to hypothesis/client that referenced this pull request Mar 10, 2017
Fix client failing to load on pages that define `self` to be something
other than `window`.

When AnnotatorJS is bundled by browserify, it is first processed by
browserify-shim* which adds references to a variable called 'global',
which exists in Node but not the browser. Browserify then processes the
result and assigns `global` to the value of the first variable from
['global', 'self', 'window'] which is already defined.

hypothesis/h#3385 fixed the problem when the
page defines a variable called 'global' that is not an alias for
'window' by reducing this list to ['self', 'window']. This still leaves
pages that define 'self'.

This commit fixes the problem by always making `global` (within CommonJS
modules) always be assigned the value of `window`.

* browserify-shim deals with the fact that AnnotatorJS 1.2.x is not a
CommonJS module and exports its entry point as `window.Annotator`.
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.

Annotator.Util undefined on pages that define a variable called global
3 participants