seagull-js / seagull

the core of the seagull framework
https://seagull-js.github.io/seagull/
GNU Lesser General Public License v3.0
10 stars 5 forks source link

React Hooks are not supported #113

Closed levito closed 5 years ago

levito commented 5 years ago

When using react hooks such as useState, the SSR will crash with the following error:

{ Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
    at invariant (<anonymous>:58502:15)
    at resolveDispatcher (<anonymous>:59850:28)
    at useState (<anonymous>:59875:20)
    at Hook (<anonymous>:517:31)
    at processChild (/PATH/TO/PROJECT/node_modules/react-dom/cjs/react-dom-server.node.development.js:2888:14)
    at resolve (/PATH/TO/PROJECT/node_modules/react-dom/cjs/react-dom-server.node.development.js:2812:5)
    at ReactDOMServerRenderer.render (/PATH/TO/PROJECT/node_modules/react-dom/cjs/react-dom-server.node.development.js:3202:22)
    at ReactDOMServerRenderer.read (/PATH/TO/PROJECT/node_modules/react-dom/cjs/react-dom-server.node.development.js:3161:29)
    at Object.renderToString (/PATH/TO/PROJECT/node_modules/react-dom/cjs/react-dom-server.node.development.js:3646:27)
    at Object.render (/PATH/TO/PROJECT/node_modules/@seagull/pages/dist/src/render.js:7:14)
    at renderUMD (/PATH/TO/PROJECT/node_modules/@seagull/routes/dist/src/RouteContext.js:50:24)
    at LazyRouteContext.render (/PATH/TO/PROJECT/node_modules/@seagull/routes/dist/src/RouteContext.js:40:22)
    at LazyRouteContext.render (/PATH/TO/PROJECT/dist/runner.js:38:13)
    at <anonymous> name: 'Invariant Violation', framesToPop: 1 }

I suspect it's 1, as currently the versions of react (16.8.1) and react-dom (16.6.0) inside seagull/pages don't match.

Steps to reproduce

  1. Create a component with hooks such as
    import * as React from 'react'
    export default function HookTest() {
    const [count, setCount] = React.useState(0)
    const increase = () => setCount(count + 1)
    return <button onClick={increase}>{count}</button>
    }
  2. Create a page using this component
  3. Navigate to that page
levito commented 5 years ago

Update: it's not the non-matching react (dom) version numbers, it still crashes after updating

levito commented 5 years ago

This is fixed now, thanks!