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.2后,开发中的项目彻底用不了了:app.model: namespace should be unique #465

Closed
longzb opened this issue Jan 4, 2017 · 11 comments

Comments

@longzb
Copy link

longzb commented Jan 4, 2017

请问下,目前有好的方法解决吗??
我喊了几个同事核实几遍了并没有重复的namespace啊!!

uncaught at _callee3 
 at _callee6 
 at takeEvery(analyze/query, _callee) 
 at _callee 
 at _callee 
 Error: Invariant Violation: app.model: namespace should be unique
    at invariant (http://localhost:8000/index.js:14900:16)
    at checkModel (http://localhost:8000/index.js:22389:32)
    at Object.injectModel (http://localhost:8000/index.js:22095:12)
    at http://localhost:8000/index.js:55300:18
    at http://localhost:8000/index.js:136:24
    at Function.requireEnsure [as e] (http://localhost:8000/index.js:597:29)
    at Function.ensure [as e] (http://localhost:8000/index.js:134:33)
    at Object.getComponent (http://localhost:8000/index.js:55299:32)
    at getComponentsForRoute (http://localhost:8000/index.js:17508:17)
    at http://localhost:8000/index.js:17520:6
    at http://localhost:8000/index.js:22197:16
    at http://localhost:8000/index.js:28091:27
    at onErrorWrapper (http://localhost:8000/index.js:22202:12)
    at sagaWithCatch$ (http://localhost:8000/index.js:22561:18)
    at tryCatch (http://localhost:8000/index.js:20492:41)
    at Generator.invoke [as _invoke] (http://localhost:8000/index.js:20783:23)
    at Generator.prototype.(anonymous function) [as throw] (http://localhost:8000/index.js:20544:22)
    at next (http://localhost:8000/index.js:26239:33)
    at Object.currCb [as cont] (http://localhost:8000/index.js:26338:8)
    at end (http://localhost:8000/index.js:26305:24)
@longzb longzb changed the title 升级1.1后,开发中的项目彻底用不了了:app.model: namespace should be unique 升级1.2后,开发中的项目彻底用不了了:app.model: namespace should be unique Jan 4, 2017
@sorrycc
Copy link
Member

sorrycc commented Jan 4, 2017

多次用 app.model 注册了同一个 namespace 的 model ?

@longzb
Copy link
Author

longzb commented Jan 4, 2017

@sorrycc 确定没有,我开始也怀疑在路由里动态注册重复的了,但我一个一个的看的确没有重复注册的,之前1.1都正常的,就是把node_modules删除后,重新npm install后就出现这个问题了。

@longzb
Copy link
Author

longzb commented Jan 4, 2017

@sorrycc 我访问的路由没有注册的model可以正常,第一次访问有动态加载model的就报不唯一的错误

@longzb
Copy link
Author

longzb commented Jan 4, 2017

@sorrycc 我切换会1.1.0就一切正常了,不知道1.1.0版本的跟vue-cli最新用roadhogrc那种配合有没有问题,没的话就用1.1算了。

@sorrycc
Copy link
Member

sorrycc commented Jan 4, 2017

给个能重现的 repo ?

@sorrycc
Copy link
Member

sorrycc commented Jan 4, 2017

#460 (comment) ,这个能解决你的问题吗?

@longzb
Copy link
Author

longzb commented Jan 5, 2017

@sorrycc @sorrycc
#460 这个能解决,但需要把下面这段代码去掉才正常。

yield call(hashHistory.push, {
    pathname: '/sys/role',
    query: newQuery
});

上面这种写法,是我之前按你的教程十几步实现crud那个教程写的,之后就一直在用,也感觉挺好使的。

现在新版本的十几步实现crud那个教程已经不用这个了。

今天试图去掉这段代码后,第一次进入有动态注册model的路由就没提示不唯一这个错误了,但路由不能多点,就比如有个用户列表,点第一次正常加载数据,点第二次就报错提示不唯一。

所以,个人理解就是,dva1.2.1有个问题就是针对动态路由不能连续加载两次。否则会出现下面两个情况:
1.model如果是动态注册,会提示namespace不唯一的错误,
2.单独把model注册放到index.js里,使用上面那段代码给地址栏添加查询参数会导致不停的加载加载路由。

@nilyang
Copy link

nilyang commented Jan 6, 2017

我在使用路由动态加载的时候也碰到了,翻了下源码,发现app.model最终实现为 injectModel,里面有个

  checkModel(m, mobile)

这个函数会检查进来的model,调用2次app.model(require('./models/foo')) 就会触发error。

我这两天折腾动态路由,我的用法是这样:

{
          path: 'dashboard',
          name: 'dashboard',
          getComponent(nextState, cb) {
            require.ensure([], require=> {
              app.model(require('./models/dashboard'))
              cb(null, require('./routes/DashBoard'))
            })
          }
        }

这样每次都动态加载路由组件,不知道这种情况怎么办?
如果app.model()可以加一个参数,强制合并或者替换会不会OK?

@kulwe
Copy link

kulwe commented Jan 6, 2017

_20170106142007
用WeakMap简单处理一下,不要直接用app.model。 App.attachedModels=new WeakMap;

@nianhua110
Copy link

#502
我在这儿写了一种方式,不知道行不行。

@sorrycc
Copy link
Member

sorrycc commented Jan 22, 2017

对动态加载的问题总结了下,有问题在 #533 里跟进。

@sorrycc sorrycc closed this as completed Jan 22, 2017
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

5 participants