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

Support for imports from isomorphic scripts #231

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jonathandewitt-dev
Copy link

@jonathandewitt-dev jonathandewitt-dev commented Mar 16, 2022

As pointed out in #230, imports on isomorphic scripts fail without any handlers for server-side code. This PR addresses that concern.

EDIT: It's worth noting that the diffs picked up far more than I actually changed. Feel free to confirm, but for sanity, here's the only difference:

var dialogPolyfill = {};

// This condition assures imports don't break for isomorphic scripts,
// while also preventing unexpected uses of this package on the server side.
if (typeof window === 'undefined') {
 function getServerSideThrower(name, isProp) {
   var error = '';
   if (isProp) {
     error = 'Cannot access property `dialogPolyfill.' + name + '` on the server side.';
   } else {
     error = 'Cannot execute `dialogPolyfill.' + name + '()` on the server side.';
   }
   return function() {
     throw new Error(error);
   }
 }
 dialogPolyfill.registerDialog = getServerSideThrower('registerDialog');
 dialogPolyfill.forceRegisterDialog = getServerSideThrower('forceRegisterDialog');
 dialogPolyfill.reposition = getServerSideThrower('reposition');
 dialogPolyfill.isInlinePositionSetByStylesheet = getServerSideThrower('isInlinePositionSetByStylesheet');
 dialogPolyfill.needsCentering = getServerSideThrower('needsCentering');
 dialogPolyfill.DialogManager = getServerSideThrower('DialogManager');
 Object.defineProperties(dialogPolyfill, {
   dm: { get: getServerSideThrower('dm', true) },
   formSubmitter: { get: getServerSideThrower('formSubmitter', true) },
   imagemapUseValue: { get: getServerSideThrower('imagemapUseValue', true) }
 });
} else {
 /* ... the original contents here ... */
}

export default dialogPolyfill;

@google-cla
Copy link

google-cla bot commented Mar 16, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

@jakec-dev
Copy link

Can this please be merged

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