troika seems to break SSR

Created on 23 May 2020  ·  11Comments  ·  Source: protectwise/troika

https://github.com/react-spring/drei/issues/25

https://github.com/react-spring/drei/issues/23

it seems to rely on document, which does not exist in node.

i believe in order to make troika pseudo-isomorphic all it would have to do is:

const linkEl = typeof document !== 'undefined' && document.createElement('a')

this would allow ssr to function normally.

All 11 comments

Thanks for the report. Am I correct in assuming that an SSR environment would not actually attempt to render the text? The suggested fix above would prevent an error on initial script module load, but would fail later on when it actually tried to use that linkEl, so I want to make sure that's not a problem.

1b005ec should do the trick, but I'd feel better with some verification before I publish a 0.26.0 release.

Yes that's correct, it just wouldn't crash. The client on the other hand has the chance to present a view immediately and it's rehydrated later on.

I'll ask them to try it out, thanks for the fix ...

I've gone ahead and published 0.26.0 with that fix, I'm fairly confident that should fix the issue after testing it by require()-ing it in the node repl. Reopen this please if it doesn't solve the issue for your users. Thanks!

thats awesome! thanks a lot, i'll re-publish my stuff as well.

Probably related, I am using nextjs and the following error occurs on startup. on v0.26

Troika createWorkerModule: web workers not allowed in current environment; falling back to main thread execution. ReferenceError: Worker is not defined
    at supportsWorkers (/Users/mk/dev/workspace/dapps/gione/node_modules/troika-worker-utils/dist/troika-worker-utils.umd.js:417:20)
    at defineWorkerModule (/Users/mk/dev/workspace/dapps/gione/node_modules/troika-worker-utils/dist/troika-worker-utils.umd.js:472:10)
    at /Users/mk/dev/workspace/dapps/gione/node_modules/troika-worker-utils/dist/troika-worker-utils.umd.js:606:30
    at /Users/mk/dev/workspace/dapps/gione/node_modules/troika-worker-utils/dist/troika-worker-utils.umd.js:2:66
    at Object.<anonymous> (/Users/mk/dev/workspace/dapps/gione/node_modules/troika-worker-utils/dist/troika-worker-utils.umd.js:5:2)

@gtolarc That should just be a console.warn not a hard error, is it causing problems?

@gtolarc I can see how that warning message would be very annoying in server logs, so I've gone ahead and suppressed it in non-browser environments: 3dedb8f2b338e9345c107831863152b115ca50d2

I've published 0.26.1 with that change.

yep, I haven't felt any other problems. and in 0.26.1, the warning message disappeared. Thank you! @lojjic

Sorry, to open this up again. I still see the console.warning in my jest tests. Anyway to suppress this?

I opened a tiny MR that checks if the process env is 'test' before console logging a failure in creating the web worker in troika-worker-utils: https://github.com/protectwise/troika/pull/85

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ocelyn picture Ocelyn  ·  13Comments

arpu picture arpu  ·  43Comments

natarius picture natarius  ·  14Comments

stephencorwin picture stephencorwin  ·  39Comments

lojjic picture lojjic  ·  11Comments