canjs / can-component

Custom elements and widgets
https://canjs.com/doc/can-component.html
MIT License
8 stars 8 forks source link

Needs Attention: can-globals used wrong #302

Closed frank-dspeed closed 5 years ago

frank-dspeed commented 6 years ago

i was experimenting again with the new ESM loader and found a little bug while async import.

can-component uses

var DOCUMENT = require('can-globals/document/document');

This should get avoided totally! because it leads to can-globals don't works as expected as document/document returns a function that returns global.document the following code posted befor inside can-component for example and all other modules that require can-global/document/document or any of ther other wrappers directly will not work

import makeDocument from 'can-vdom/make-document/make-document';
import globals from 'can-globals';
globals.setKeyValue('document',makeDocument());
import DOCUMENT from 'can-globals/document/document';
globals.getKeyValue('document') //=> retuns document
//=> DOCUMENT === 'undefined'

can-component.js

var globals  = require('can-globals');
var DOCUMENT = globals.getKeyValue('document') 

because the wrapper returns the befor mentoined function so i would say always import globals and use globals.getKeyValue('document') same for location

Summary

can-globals/document/document gets importet in some can-* components and returns a function that returns getKeyValue('global').document this should not be the case it should return getKeyValue('document') same for location

justinbmeyer commented 6 years ago

Thanks for posting. Can you clean up this explination? I’m not really sure what this says.