XiNiHa / vilay

Vite SSR framework with support for React SSR streaming and Relay
https://vilay.xiniha.dev
MIT License
55 stars 4 forks source link

Crash issue when in dev mode. #1

Closed wickedev closed 2 years ago

wickedev commented 2 years ago

In dev mode the process dies randomly for two reasons, one is Cannot set headers after they are sent to the client and the other is React SSR Error Invariant Violation: useRelayEnvironment: Expected to have found a Relay environment provided by a 'RelayEnvironmentProvider' component. There is no problem when I try with curl , but when I try with chrome the node process dies. The process does not die when in prod mode. Below is the output

$ yarn dev
Server running at http://localhost:3000
[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

Error: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:371:5)
    at ServerResponse.setHeader (node:_http_outgoing:576:11)
    at sendError (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/h3-npm-0.3.8-e7615d0af3/dist/index.cjs:554:7)
    at /Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/h3-npm-0.3.8-e7615d0af3/dist/index.cjs:566:14
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_HTTP_HEADERS_SENT'
}
$ yarn dev
Server running at http://localhost:3000
[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?
React SSR Error Invariant Violation: useRelayEnvironment: Expected to have found a Relay environment provided by a `RelayEnvironmentProvider` component. This usually means that useRelayEnvironment was used in a component that is not a descendant of a `RelayEnvironmentProvider`. Please make sure a `RelayEnvironmentProvider` has been rendered somewhere as a parent or ancestor of your component.
    at invariant (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/invariant-npm-2.2.4-717fbdb119/invariant.js:40:15)
    at useRelayEnvironment (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-relay-virtual-578c22279e/lib/relay-hooks/useRelayEnvironment.js:23:64)
    at Proxy.usePreloadedQuery (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-relay-virtual-578c22279e/lib/relay-hooks/usePreloadedQuery.js:39:21)
    at Page (/pages/index.page.tsx:17:38)
    at renderWithHooks (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:5387:16)
    at renderIndeterminateComponent (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:5460:15)
    at renderElement (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:5676:7)
    at renderNodeDestructive (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:5815:11)
    at retryTask (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:6168:5)
    at performWork (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:6215:7) {
  framesToPop: 1
}
node:events:368
      throw er; // Unhandled 'error' event
      ^

Invariant Violation: useRelayEnvironment: Expected to have found a Relay environment provided by a `RelayEnvironmentProvider` component. This usually means that useRelayEnvironment was used in a component that is not a descendant of a `RelayEnvironmentProvider`. Please make sure a `RelayEnvironmentProvider` has been rendered somewhere as a parent or ancestor of your component.
    at invariant (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/invariant-npm-2.2.4-717fbdb119/invariant.js:40:15)
    at useRelayEnvironment (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-relay-virtual-578c22279e/lib/relay-hooks/useRelayEnvironment.js:23:64)
    at Proxy.usePreloadedQuery (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-relay-virtual-578c22279e/lib/relay-hooks/usePreloadedQuery.js:39:21)
    at Page (/pages/index.page.tsx:17:38)
    at renderWithHooks (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:5387:16)
    at renderIndeterminateComponent (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:5460:15)
    at renderElement (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:5676:7)
    at renderNodeDestructive (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:5815:11)
    at retryTask (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:6168:5)
    at performWork (/Users/wickedev/Workspace/vite-ssr-relay-template/node_modules/.store/react-dom-virtual-e16f6f0751/cjs/react-dom-server.node.development.js:6215:7)
Emitted 'error' event on Writable instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  framesToPop: 1
}
wickedev commented 2 years ago

As a further explanation, there is no problem when installing the package and the first yarn dev. It seems to happen after the second time.

XiNiHa commented 2 years ago

Does performing yarn vite clean > Ctrl+C > yarn dev solve the issue? I'm not sure what's the cause, but I think I had the same issue and solved by doing that. I can't investigate the issue right now since I didn't bring my laptop. If that doesn't solve your issue then I'll look at the issue tomorrow.