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

Duplicate state registration on initialization #13

Open
caffed opened this issue Jul 3, 2020 · 1 comment
Open

Duplicate state registration on initialization #13

caffed opened this issue Jul 3, 2020 · 1 comment

Comments

@caffed
Copy link

caffed commented Jul 3, 2020

Hi there,

I am using this as part of Electron based application.
I am not sure if I am the only one, but I've encountered a duplicate state error when configuring this.

Error: State '${state.name}' is already defined
    at StateQueueManager.register (/home/user/projects/project-electron/node_modules/@uirouter/core/lib/state/@uirouter/core/state/stateQueueManager.ts:35:15)
    at StateRegistry.register (/home/user/projects/project-electron/node_modules/@uirouter/core/lib/state/@uirouter/core/state/stateRegistry.ts:128:28)
    at eval (webpack-internal:///./node_modules/@uirouter/redux/lib/react/ConnectedUIRouter.js:30:49)
    at Array.forEach (<anonymous>)
    at ConnectedUIRouter (webpack-internal:///./node_modules/@uirouter/redux/lib/react/ConnectedUIRouter.js:29:12)
    at renderWithHooks (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:14803:18)
    at mountIndeterminateComponent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:17482:13)
    at beginWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:18596:16)
    at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:188:14)
    at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:237:16)

Upon further inspection it looks like ConnectedUIRouter registers states without checking for their existence first.

Changing this:
https://github.com/ui-router/redux/blob/master/react/ConnectedUIRouter.tsx#L35-L37

    (states || []).forEach(state =>
      router.current.stateRegistry.register(state)
    );

to this:

    (states || [])
      .filter(state => !Boolean(router.current.stateRegistry.get(state.name)))
      .forEach(state => router.current.stateRegistry.register(state));

works for me.

@kadamgreene
Copy link

I'm seeing the same issue.

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