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

troika seems to break SSR #46

Closed
drcmda opened this issue May 23, 2020 · 11 comments
Closed

troika seems to break SSR #46

drcmda opened this issue May 23, 2020 · 11 comments

Comments

@drcmda
Copy link
Contributor

drcmda commented May 23, 2020

pmndrs/drei#25

pmndrs/drei#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.

@lojjic
Copy link
Collaborator

lojjic commented May 24, 2020

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.

lojjic added a commit that referenced this issue May 24, 2020
… present

This makes the link element creation lazy, and falls back to a no-op when there
is no browser DOM available, e.g. in React server-side rendering, so that just
loading the script does not throw an error.
@lojjic
Copy link
Collaborator

lojjic commented May 24, 2020

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

@drcmda
Copy link
Contributor Author

drcmda commented May 24, 2020

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 ...

@lojjic
Copy link
Collaborator

lojjic commented May 24, 2020

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!

@lojjic lojjic closed this as completed May 24, 2020
@drcmda
Copy link
Contributor Author

drcmda commented May 24, 2020

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

@gtolarc
Copy link

gtolarc commented May 26, 2020

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)

@lojjic
Copy link
Collaborator

lojjic commented May 26, 2020

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

@lojjic
Copy link
Collaborator

lojjic commented May 26, 2020

@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: 3dedb8f

I've published 0.26.1 with that change.

@gtolarc
Copy link

gtolarc commented May 27, 2020

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

@albert-schilling
Copy link

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

@albert-schilling
Copy link

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: #85

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

4 participants