preactjs / preact-compat

ATTENTION: The React compatibility layer for Preact has moved to the main preact repo.
http://npm.im/preact-compat
MIT License
949 stars 148 forks source link

Preact Compat works on Server Side but not on Client Side #416

Closed csantany closed 5 years ago

csantany commented 7 years ago

Hi, I just tried to implement preact-compat using webpack like this:

resolve.alias = {
      'react': 'preact-compat',
      'react-dom': 'preact-compat'
};

Everything looks good on the server side, but for some reason on the client is not working properly (if you see my gif, you'll see that on the first load you can see the content but after a second removes everything and if I inspect the HTML I got

Any idea?

Thanks, Carlos.

FallOutChonny commented 7 years ago

Did you solve it? I have same issue in my SSR project 😢

csantany commented 6 years ago

Not yet and looks like this project is not maintained any more, I continue using React.

developit commented 6 years ago

This is likely caused by code splitting, which means there'd be no difference when using preact or react.

FallOutChonny commented 6 years ago

I think this is caused by module alias incorrect because I've solved it. your server-side is still using react-dom but client-side use preact-compat

developit commented 6 years ago

yup - have also seen that! it'll cause the root element to be rendered differently, which dumps the whole tree and re-renders on the client. While it's not a great symptom, that's actually the correct behavior for Preact (mismatched root shouldn't reuse elements).

csantany commented 6 years ago

I tried one more time with my current project, and my results are pretty much the same, works perfect the Server Side Rendering, but the Client Side just give me a blank page.

I'm using React 16.0.0 (hydrate)

With SSR:

screen shot 2017-12-27 at 4 10 33 pm

screen shot 2017-12-27 at 4 10 44 pm

With Client Side:

screen shot 2017-12-27 at 4 10 59 pm

screen shot 2017-12-27 at 4 11 07 pm

csantany commented 6 years ago

@developit why you gave me a 👎 , when I said this project is not maintained or they don't care about issues, is because took 4 months even to receive a response :/

csantany commented 6 years ago

@FallOutChonny how exactly did you solved?

cdaringe commented 6 years ago

i have completely stripped react/react-dom from my project, and i still suffer these symptoms. what debug data can i provide?

developit commented 6 years ago

@csantany because it was an unappreciative comment. preact-compat is a community project, not a corporate-sponsored endeavor, and as such it depends on volunteers for maintenance. Many of the volunteers here don't use preact-compat extensively and prefer to only use the preact core ecosystem.

The original gif was pretty hard to see, but I just looked again and I'm seeing an <undefined> component, which generally happens if an Object is present in the Virtual DOM tree that isn't a valid component. Most often this is a result of importing a non-existent default export (import foo from './foo' where './foo has no default export), or using something like Fragments that preact doesn't support.

@cdaringe I know you've probably moved on from this issue, but I figured I'd mention that in this case if you can select the root element of your DOM in DevTools' Elements panel, then log out $0._component you should be able to see the offending Virtual DOM tree.