On tv.nrk.no, we render most of our markup server side. When attempting to render an instance of core suggest on the server, we get the following error:
fatal error ReferenceError [Error]: navigator is not defined
This is due to the following lines of code:
var IS_BROWSER = typeof window !== 'undefined';
IS_BROWSER && /(android)/i.test(navigator.userAgent); // Bad, but needed
IS_BROWSER && /iPad|iPhone|iPod/.test(String(navigator.platform));
var IS_IE11 = IS_BROWSER && window.msCrypto; // msCrypto only exists in IE11
If I remove the above-mentioned lines of code, the problem persists, all due to the fact that window is present.
I'm not entirely sure how to deal with this issue – and maybe it's even not a core-suggest thing, but I'd love some feedback and maybe we could solve this together. It would be great if we could use core-suggest on the new search page on tv.nrk.no, still utilising server side rendering. Perhaps the IS_BROWSER test could test for more than just the presence of window?
Description
On tv.nrk.no, we render most of our markup server side. When attempting to render an instance of core suggest on the server, we get the following error:
fatal error ReferenceError [Error]: navigator is not defined
This is due to the following lines of code:
... which in turn is caused by the fact that we already have a global object named
window
on the server to get server side rendering of web components to work. This is the shim we use: https://github.com/popeindustries/lit/blob/main/packages/lit-html-server/src/dom-shim.jsIf I remove the above-mentioned lines of code, the problem persists, all due to the fact that
window
is present.I'm not entirely sure how to deal with this issue – and maybe it's even not a
core-suggest
thing, but I'd love some feedback and maybe we could solve this together. It would be great if we could usecore-suggest
on the new search page on tv.nrk.no, still utilising server side rendering. Perhaps theIS_BROWSER
test could test for more than just the presence ofwindow
?