Skip to content

Getting JSON parse error when calling events with no parameters after upgrade #55

@slikk66

Description

@slikk66

What is the current behavior:
Hi, just upgraded to:

        "effector": "^22.1.1",
        "effector-logger": "^0.12.1",
        "effector-react": "^22.0.4",

Please provide the steps to reproduce and if possible a minimal demo of the problem via https://share.effector.dev, https://codesandbox.io or similar

export const resetSurvey = createEvent();

export default createStore<surveyStore>(emptySurveyStore)
    .on(resetSurvey, (state) => {
        return {
            ...state,
        };
    })

What is the expected behavior:
With the above snippet, nothing should change. However I'm getting a JSON parse error show in the console here:

$events
  .on(eventAdd, (map, payload) => ({
    ...map,
    [payload.name]: {
      mapped: payload.mapped,
      history: [],
    },
  }))
  .on(eventTriggered, (map, { name, params }) => {
    // should not change the order of fields

    map[name] = {
      ...map[name],
      history: [JSON.parse(JSON.stringify(params)), ...map[name].history],     <--- here
    };
    return { ...map };
  });

I'm guessing since the event has no params, it's trying to stringify/parse a null/undefined and that is causing the error.

Which versions of effector packages, and which browser and OS are affected by this issue? Did this work in previous versions of effector?:
yea used to work, I just reverted back to these and not seeing the error again

        "effector": "^21.8.5",
        "effector-logger": "^0.10.0",
        "effector-react": "^21.2.1",

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions