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

ng2-semantic-ui & Universal #185

Closed
neoswf opened this issue Jul 20, 2017 · 6 comments
Closed

ng2-semantic-ui & Universal #185

neoswf opened this issue Jul 20, 2017 · 6 comments

Comments

@neoswf
Copy link

neoswf commented Jul 20, 2017

Installing SUI on a NG4 & Universal project. There's a problem with the window reference inside SUI. It breaks Universal builds.

One of universal principals Gotchas is the prohibition usage of the window object. (referance).

Error I'm receiving is when trying to build a universal build:

ReferenceError: MouseEvent is not defined
    at /Users/username/Projects/app/node_modules/ng2-semantic-ui/bundles/ng2-semantic-ui.umd.min.js:3:1190
    at at.datepicker.months (/Users/username/Projects/app/node_modules/ng2-semantic-ui/bundles/ng2-semantic-ui.umd.min.js:1:69)
    at Object.<anonymous> (/Users/username/Projects/app/node_modules/ng2-semantic-ui/bundles/ng2-semantic-ui.umd.min.js:1:369)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)

Searching over this error, I discovered several discussions over other ng projects, like ng2-select, or ngx-bootstrap 1, ngx-bootstrap 2,

What's your position regarding this matter? Is it something that can be fixed in SUI?

@edcarroll
Copy link
Owner

I'd definitely like Universal to be something supported by this library, though at the moment I have no experience with it so can't really estimate the amount of work required.

Might you be able to please set up a repo that I can clone that has this library set up in the context of universal, so I can debug from there?

@neoswf
Copy link
Author

neoswf commented Jul 20, 2017

Sure. No problem. I'll do that and post here.
Meanwhile I'd like to share results of my investigation. Approaches other people used to resolve this issue:

  1. First example is Universal documentation, where calling code based on the platform is an option (but seems to me irrelevant to us, since its not modular, and needs to be called outside of each SUI component's scope.
import { PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
 
constructor(@Inject(PLATFORM_ID) private platformId: Object) { ... }
 
ngOnInit() {
   if (isPlatformBrowser(this.platformId)) {
      // Client only code.
      ...
   }
   if (isPlatformServer(this.platformId)) {
     // Server only code.
     ...
   }
}
  1. After that we got this example, which seems to be the common hack i encountered in all my research.
import {global} from 'angular2/src/facade/lang';
/* tslint:disable */
const KeyboardEvent = (global as any).KeyboardEvent as KeyboardEvent;
/* tslint:enable */
  1. Another implementation of this approach: tirelibrary/ngx-charts@5211283

  2. BUT for some reason it seems that the previous approach breaks systemjs and aot - fix(dropdown,rating,typeahead): remove global in order to be usable … valor-software/ngx-bootstrap#1734

  3. another working hack i have discovered is this one, where they overwrite the event with an empty array.

@neoswf
Copy link
Author

neoswf commented Jul 20, 2017

Have discovered a great way to integrate SUI inside an Universal+CLI project. Please find here a repo that demonstrate how to perform that: https://github.com/pquarme/cli-universal-demo

Heres a post in SO that explains a little regarding the architecture.
https://stackoverflow.com/questions/44330537/need-browseranimationsmodule-in-angular-but-gives-error-in-universal

Good luck 👍

@ebondu
Copy link

ebondu commented Aug 17, 2017

Hi,
I am facing the same issue. I looked at solutions proposed by @neoswf but I am not able to found a workaround without modifying the lib. @neoswf, how did you integrate SUI to pquarme/cli-universal-demo? I tried to add SUI in this project but without success. To me, the approach 2) seems to be the simplest and should not be to difficult to integrate to the lib.

@neoswf
Copy link
Author

neoswf commented Aug 21, 2017

Hi @ebondu. We have deserted universal. One big messy project, bad documented, bad managed, bad everything. Its a nightmare to work with and we abandoned it in favour of https://github.com/GoogleChrome/puppeteer. Easy to use, integrate with CLI, etc.

@ebondu
Copy link

ebondu commented Aug 21, 2017

Hi, thanks for your feedback and I agree with you ;). I will have a look to the puppeteer. @edcarroll I adapted the semantic-ui lib to be compatible with universal / aot compile, but I didn't test all components, etc. (dirty way). But if you are interrested, I can send you a PR...

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