szmarczak / cacheable-lookup

A cacheable dns.lookup(…) that respects TTL :tada:
MIT License
193 stars 29 forks source link

fix render page with angular12 universal (SSR) #59

Open a-shpota opened 2 years ago

a-shpota commented 2 years ago

Problem: Has problem on use package with Zone.js of angular universal. Server (SSR) don`t render page while there are active ones zone.js macrotask.

Removed using setInterval & setTimeout

szmarczak commented 2 years ago

Does Zone.js just replace the globals or monkey-patch the Node.js modules as well? I mean: could we just add

const {setTimeout, setInterval} = require('timers');

at the beginning?

a-shpota commented 2 years ago

yes, timers monky-patched by zone.js, and needed for working ChangeDetection mechanism of angular.

szmarczak commented 2 years ago

It seems that it just works with .unref() so no changes should be required?

import 'zone.js';

Zone.current.run(() => {
        setTimeout(() => {
                console.log('foobar');
        }, 1000).unref();
});

// Uncomment this and foobar will be logged:
// setTimeout(() => {}, 1100);
szmarczak commented 2 years ago

I just tested

import 'zone.js';
import CacheableLookup from 'cacheable-lookup';

const cacheable = new CacheableLookup();

Zone.current.run(() => {
        cacheable.lookup('google.com', console.log);
});

and it exists right away. Are you sure it is cacheable-lookup that is keeping the zone busy?

a-shpota commented 2 years ago

i prepare repo for reproducing case and hope you can help me find the right solution

https://github.com/a-shpota/cacheable-reproduce

npm ci && npm run build:ssr && npm run serve:ssr and try render page with request curl -v "http://localhost:4000"

in console print pending makrotasks with trace

entrypoint server.ts

szmarczak commented 2 years ago

I got

npm ERR! code ENOTFOUND
npm ERR! syscall getaddrinfo
npm ERR! errno ENOTFOUND
npm ERR! network request to http://registry.rozetka.company/repository/npm-rzk-proxy/yargs-parser/-/yargs-parser-13.1.2.tgz failed, reason: getaddrinfo ENOTFOUND registry.rozetka.company

when running npm ci, is this expected?

a-shpota commented 2 years ago

no, sorry. We used cacheable proxy. Fixes pushed