-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
10.0.0-alpha.1 - __hooks of undefined with render-to-string #1373
Comments
Had a look into this and the issue is that we never set |
Awesome catch, was looking at your PR this morning. |
Version 5.0.1 for |
Looks like the issue is not completely fixed. @vaneenige send this test case on slack https://codesandbox.io/s/k9mk2rloqr |
yes experiencing same issue with version 5.0.1 |
Fixed in preactjs/preact-render-to-string#77 👍 |
Was this ever resolved? I still get the undefined error, with a built package. hooks.module.js:1 Uncaught TypeError: Cannot read property '__H' of undefined
at r (hooks.module.js:1)
at i (hooks.module.js:1)
at o (hooks.module.js:1)
at S.p [as constructor] (index.js:6)
at S.x [as render] (preact.min.js:1)
at j (preact.min.js:1)
at C (preact.min.js:1)
at N (preact.min.js:1)
at _ (preact.min.js:1)
at v (preact.min.js:1)
|
@didymu5 yes by using the new version of render-to-string |
I see you're using Preact X, to get this to work you will need to install the |
Thanks for responding. hmm... here's what I have now. Same result.
|
I should also add that I'm not really using render-to-string. Instead I used the widget template from the preact-cli |
sorry, the widget template is a bit broken because |
Hi, @marvinhagemeister the issue is still present |
By the way it worked using this which i have found here https://github.com/preactjs/cli-demo |
Leaving this for the next person who makes the mistake I made: If you are new to Preact and you found this bug by searching "Cannot read property '__H' of undefined" on Google: That error message can also happen if you call |
Thanks for pointing folks in the right direction @mcclure! I wonder if it would be worth creating a page on preactjs.com that lists out common error messages with fixes for each? That way anyone googling gets a nice resource with a clear answer. |
I've landed here because of
the cause was vs-code auto-import looking like this import { useState, useCallback } from 'preact/hooks/src';
// instead of this
import { useState, useCallback } from 'preact/hooks'; |
Didn't want to open a new issue for this, has a similar compilation issue, due to the same reason.
|
There's an odd bug when using hooks together with
render-to-string
.What I had was a simple component with the
useState
hook. Rendered on the client this was fine, on the server it resulted in:Uncaught TypeError: Cannot read property '__H' of undefined
.At first I thought this had something to do with
render-to-string
because the error also occurred when I replaced preact's render function on the client withrender-to-string
. After some more investigation this wasn't actually a bug in that library but rather inpreact/hooks
, let me explain:The
__H
in the error stands for__hooks
that can't be read becausecurrentComponent
is undefined. This is defined when you use preact's render function. In this codesandbox you can see that at firstrender-to-string
throws the error, after that the same component renders fine (normal render function), thenrender-to-string
works!The text was updated successfully, but these errors were encountered: