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

在开发模式下的一些问题 #1

Open
zhuscat opened this issue Jan 5, 2017 · 2 comments
Open

在开发模式下的一些问题 #1

zhuscat opened this issue Jan 5, 2017 · 2 comments

Comments

@zhuscat
Copy link

zhuscat commented Jan 5, 2017

按着你的思路正在实现一个 boilerplate,发现一些问题,nodemon 只是在监听 server 目录下的代码,但是 server 也承担着服务器渲染的工作,会用到 client 下的代码,所以说会出现下面的一些问题:

  1. 本来客户端代码就有错误,此时运行服务器会崩溃,此时就算改正 client 下的代码也没有用,因为 nodemon 监听的是 server 下的代码,这时必须自己重启服务器
  2. 正常运行之后,修改客户端代码可以实现热替换,但如果刷新一个页面,会从服务器端拉取数据,服务器端返回的还是之前没有修改过代码生成的html,接着React 会发现服务器端返回的跟客户端返回的出现不一致,发出一个警告,如下:

2017-01-05 11 29 42

更新:

看了一下 README 提到了上面的问题,这个问题没有什么解决办法么?😑

@chikara-chan
Copy link
Owner

chikara-chan commented Jan 5, 2017

这个问题我也是研究了很久,目前无法解决,即使可以解决,服务端重启再打包会比较耗时,所以也没必要解决

@zhuscat
Copy link
Author

zhuscat commented Jan 5, 2017

@chikara-chan 这是 @wssgcg1213 写的一个boilerplate,这里面用的是同时监听两个端的代码,并且清除 require 缓存,https://github.com/wssgcg1213/koa2-react-isomorphic-boilerplate/blob/master/bin/development.js#L61, 这可以解决修改客户端代码后,可以热更新,服务器端返回html也会变化,但是使用这个boilerplate的时候,我遇到的一个问题是,我使用 mongoose,当任何代码发生变动,会抛出 Cannot overwrite model once compiled Mongoose 的错误。经过研究发现 mongoose 会在 mongoose.modelsmongoose.modelSchema 下面缓存你之前定义的模型,所需这种方法下面必须在清楚缓存的时候删除 mongoose 的缓存,自己感觉也不是很完美。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants