wKoza / ngx-upload

Ngx-upload is an upload module for Angular Ivy ready
30 stars 15 forks source link

Angular Universal (SSR) compatibility #72

Closed ilueckel closed 4 years ago

ilueckel commented 4 years ago

Fixed NgxDragAndDropDirective breaking SingleSiteRendering (SSR) in Angular universal. Using @HostListener breaks Angular universal

        Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__metadata"])("design:paramtypes", [Event]),
                                                                                       ^

ReferenceError: Event is not defined

So I removed all Event-Types and @HostListeners, injected the platform ID and added event listening via Renderer2 when the platform is a browser.

codecov-io commented 4 years ago

Codecov Report

Merging #72 into master will increase coverage by 0.19%. The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #72      +/-   ##
==========================================
+ Coverage   63.22%   63.42%   +0.19%     
==========================================
  Files          10       10              
  Lines         416      421       +5     
  Branches       56       57       +1     
==========================================
+ Hits          263      267       +4     
  Misses        125      125              
- Partials       28       29       +1
Impacted Files Coverage Δ
src/directives/dropzone.directive.ts 72.46% <90%> (+0.58%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 109e40e...e183401. Read the comment docs.

wKoza commented 4 years ago

Hi @ilueckel , You will need to add some polyfills like this in sever.ts:

const win = domino.createWindow(template);
global['window'] = win;
global['navigator'] = win.navigator;
global['Event'] = win.Event;
ilueckel commented 4 years ago

You could do that - but it's another (useless) dependency in your build step. And even worse: Even if you integrate domino the result is, well, useless. Because you don't need server side drag-and-drop events on this control. It all happens in the users browser. This also would not be an out-of-the-box solution for Angular builds.

wKoza commented 4 years ago

Okay, here we go !