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

Add docs about page keeping auto refreshing #266

Closed
frog-o opened this issue Feb 20, 2022 · 16 comments
Closed

Add docs about page keeping auto refreshing #266

frog-o opened this issue Feb 20, 2022 · 16 comments

Comments

@frog-o
Copy link

frog-o commented Feb 20, 2022

about every 6 second my page refresh and i have no clue how to turn this off. Just download and followed your tutorial

@brillout
Copy link
Member

This is probably a Vite issue. Do you also have this with npm init vite@latest?

@frog-o
Copy link
Author

frog-o commented Feb 20, 2022

I just tried the latest here is my package.json.
I still have it doing annoying refresh have no clue how to troubleshoot try upgrade typescript to latest beta tried upgrade ts-node. I still very new to node env. I don't undestand at all how ts-node find wich script to execute it pointing to a directory
"scripts": {
"dev": "npm run server",
"prod": "npm run build && npm run server:prod",
"build": "vite build && vite build --ssr",
"server": "ts-node ./server",
"server:prod": "cross-env NODE_ENV=production ts-node ./server"
},
"dependencies": {
"@types/compression": "^1.7.2",
"@types/express": "^4.17.13",
"@types/node": "^17.0.17",
"@vitejs/plugin-vue": "^2.2.0",
"@vue/compiler-sfc": "^3.2.31",
"@vue/server-renderer": "^3.2.31",
"compression": "^1.7.4",
"cross-env": "^7.0.3",
"express": "^4.17.2",
"ts-node": "^10.5.0",
"typescript": "^4.5.5",
"vite": "latest",
"vite-plugin-ssr": "^0.3.54",
"vue": "^3.2.31"
}

@brillout
Copy link
Member

As I said, I don't think it's related to vite-plugin-ssr.

@frog-o
Copy link
Author

frog-o commented Feb 20, 2022

I don't think so either but I think I have an idea of what it is now @brillout,

Even if it not your problem it make a very bad user experience and a very unwelcoming one at that.
All I want to do is help.
I feel this type of thing make your plugin look bad even if it not your problem.

I found this issue after much looking.
Which is the same error i am getting. Vite does not mention it uses websocks in there documentions.

Could you somewhere in your documentation say

if you have problem with page refresh make sure web browser is connecting to the websocket; If it fails it keep trying and refreshing see more about this issue here

I think this is going to happen to anyone run vite in a container.

This is all I am asking for, You said

but as do-one-thing-do-it-well Vite plugin.

I think add info on how to debug this is going to help enforce this point of view.

@brillout
Copy link
Member

Good point, I will create a new Troubleshooting section.

@brillout brillout reopened this Feb 20, 2022
@frog-o
Copy link
Author

frog-o commented Feb 20, 2022

Thankyou a lot

@brillout brillout changed the title page keeps auto refreshing Add docs about page keeping auto refreshing Feb 20, 2022
@brillout
Copy link
Member

👍 And please let me know if you find other such paper cuts. I do want to polish vps.

I'm going to implement the Troubleshooting section after I release Vike.

@frog-o
Copy link
Author

frog-o commented Feb 26, 2022

I Just figure things out

I also asked vite for troubleshooting section here
since i believe it is there error.

I found out that the issue I point you to was lock I was going to commit there about how I had the same problem and ask them to add a troubleshoot section.

Most of my problem occur because of 2 things

1.) I am trying to program over a local network I have vite listen to 0.0.0.0
2.) I have it running in a systemd container (I think systemd sets up a nat by default.)

I have to allow systemd to allow traffic from the ports I want to use so far I open up 2.

  1. one for vite to listen on
  2. another for websocket.

I add this to my config

const config: UserConfig = {
  plugins: [vue(), ssr()],
  server: {
    port: portFrombullet1,
    host:"0.0.0.0",
    watch: {usePolling: true},
    hmr:{port:portFrombullet2},
    strictPort: true
  }
}

This setting I believe are commonly untested because it is consider a security hole. But Ironically IMHO it create one. This is bad for many reason the main one is If you are using a local network you should not have to hook up vite to use the internet and your going to need to listen to the outside world in odder to do it. I could make it a little safer by just listen to one ip address but since I am trying to trouble shoot i figure to listen to them all. It has no domain name and I am running it only when I working on it. And I believe I am behind 2 nats with an uncommon port number. I am using a raspberry pi in headless mode. It has to run in a container in odder for me to use 64-bit or I need to reinstall the system and start from scratch. Working from a container I believe is safer.

There is no such thing a completely secure unless you don't use it and even that not completely safe.

I was getting

TypeError: Cannot read properties of null

from vite hydrate process..

this was the stack trace 

logError (runtime-core.esm-bundler.js:218)
handleError (runtime-core.esm-bundler.js:204)
renderComponentRoot (runtime-core.esm-bundler.js:922)
hydrateSubTree (runtime-core.esm-bundler.js:5002)
componentUpdateFn (runtime-core.esm-bundler.js:5023)
run (reactivity.esm-bundler.js:167)
setupRenderEffect (runtime-core.esm-bundler.js:5156)
mountComponent (runtime-core.esm-bundler.js:4939)
hydrateNode (runtime-core.esm-bundler.js:4124)
hydrateChildren (runtime-core.esm-bundler.js:4257)
hydrateElement (runtime-core.esm-bundler.js:4219)
hydrateNode (runtime-core.esm-bundler.js:4115)
hydrateChildren (runtime-core.esm-bundler.js:4257)
hydrateElement (runtime-core.esm-bundler.js:4219)
hydrateNode (runtime-core.esm-bundler.js:4115)
hydrateSubTree (runtime-core.esm-bundler.js:5009)
componentUpdateFn (runtime-core.esm-bundler.js:5023)
run (reactivity.esm-bundler.js:167)
setupRenderEffect (runtime-core.esm-bundler.js:5156)
mountComponent (runtime-core.esm-bundler.js:4939)
hydrateNode (runtime-core.esm-bundler.js:4124)
hydrateSubTree (runtime-core.esm-bundler.js:5009)
componentUpdateFn (runtime-core.esm-bundler.js:5023)
run (reactivity.esm-bundler.js:167)
setupRenderEffect (runtime-core.esm-bundler.js:5156)
mountComponent (runtime-core.esm-bundler.js:4939)
hydrateNode (runtime-core.esm-bundler.js:4124)
hydrate2 (runtime-core.esm-bundler.js:4039)
mount (runtime-core.esm-bundler.js:3874)
app.mount (runtime-dom.esm-bundler.js:1609)
hydrate (_default.page.client.ts:13)
await in hydrate (async)
(anonymous) (_default.page.client.ts:6)

I found out this was caused by me using clientPort instead of port in hmr server section in my config.

I just post this to let people who might have this problem know there not alone; Maybe I am the only one because I am just weird and won't bow down to how thing are typical done.

Like I said not your problem but thought you might want to know, I am ecstatic I finally able to get this to work.

@brillout
Copy link
Member

brillout commented Feb 26, 2022

@frog-o 👍

@frog-o
Copy link
Author

frog-o commented Feb 27, 2022

something that i wanted to do was add fastify instead of express I had to change index.ts to this
and run

>yarn add fastify and middie @types/aws-lambda

import Fastify from 'fastify'
import middie from 'middie'
import compression from 'compression'
import { createPageRenderer } from 'vite-plugin-ssr'

const isProduction = process.env.NODE_ENV === 'production'
const root = `${__dirname}/..`

startServer()
//I am still learn javscript, node etc but i got rid of use
// and replaced it with register wich i beleave does the same thing.
//frog-o
async function startServer() {
  const app = Fastify()
  await app.register(middie)
  await app.register(compression)

  let viteDevServer
  if (isProduction) {
    app.register(require('fastify-static'), {
    root: `${root}/dist/client`,
    
    })
  } else {
    const vite = require('vite')
    viteDevServer = await vite.createServer({
      root,
      server: { middlewareMode: 'ssr' },
    })
    app.use(viteDevServer.middlewares)
  }

  const renderPage = createPageRenderer({ viteDevServer, isProduction, root })
  app.get('*', async (req, res) => {
    const url = req.url
    const pageContextInit = {
      url,
    }
    const pageContext = await renderPage(pageContextInit)
    const { httpResponse } = pageContext
    if (!httpResponse) return res.status(405)
    const { body, statusCode, contentType } = httpResponse
    res.status(statusCode).type(contentType).send(body)
  })

  const port = parseInt(process.env.PORT ??= "tomyPort")
  const host = process.env.HOST ??= "0.0.0.0"
  app.listen(port,host)
  console.log(`Server running at ${host}:${port}`)

This does not work on you production target. Looking at vite doc dosen't help. Your are doing a lot I don't understand.

  • where is index.html
  • in the package.json "build": "vite build && vite build --ssr", why is ssr empty sould it not point to _default.page.client.js or something
  • in the package.json there "server:prod": "cross-env NODE_ENV=production ts-node ./server" why does it point to dir instead of server.js or server.ts

yarn 3 dose not work in PNP mode a real bummer. I have to add
nodeLinker: "pnpm" in my .yarnrc.yml I report to yarn here

@brillout
Copy link
Member

@frog-o Try to find the answers on your own before asking stuff

@frog-o
Copy link
Author

frog-o commented Mar 5, 2022 via email

@brillout
Copy link
Member

brillout commented Mar 5, 2022

I agree but the problems you mentioned are unrelated to vps

@frog-o
Copy link
Author

frog-o commented Mar 5, 2022 via email

@frog-o
Copy link
Author

frog-o commented Mar 29, 2022

In odder to help with docs of my problem I mention above it is also mention here I am still looking for answers and I thought it might be helpful if anyone is following this.

@brillout
Copy link
Member

Closing for lack of interest.

@brillout brillout closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants