Skip to content

useReducer id containing '/' causes state to be undefined #87

@plnuinsure

Description

@plnuinsure

Bug

Passing an id containing a forward slash (/) as the 4th argument to useReducer causes the returned state to be undefined, breaking any component that reads from it.

To reproduce

import { useReducer } from 'reinspect';

const [state, dispatch] = useReducer(reducer, initialState, undefined, 'MySlice/UpdateState');

console.log(state); // undefined

Expected behaviour

state should be the initial state (initialState), as it is when the id does not contain a /.

Actual behaviour

state is undefined, causing runtime errors in any component that accesses properties on it (e.g. Cannot read properties of undefined).

Workaround

Removing the / from the id fixes the issue:

const [state, dispatch] = useReducer(reducer, initialState, undefined, 'MySlice UpdateState');

Notes

The / character is used by Redux Toolkit as a namespace separator in action types (e.g. slice/action). It is likely that reinspect is parsing the id as a Redux action type and mishandling the namespace separator, resulting in the state not being correctly initialised.

Environment

  • reinspect: 1.1.0
  • React: 16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions