3

I've been struggling over this error for a while now. It happens when I try to open react-bootstrap Modal with dynamically passed lazy component referrence and props to render it inside. It worked with classic import.

enter image description here

First row points to some react's internal lazy handler:

enter image description here

This is how modals are handled inside my ModalProvider:

const ModalList = React.memo(({ modalList, closeModalByIndex, confirmModalExitByIndex }) =>
    modalList.map((modalDef, index) => {
        const closeModal = () => closeModalByIndex(index);
        const onConfirmExitChange = (confirmExit) => confirmModalExitByIndex(index, confirmExit);
        const props = { ...modalDef, key: index, closeModal, onConfirmExitChange };
        switch (modalDef.type) {
            case TYPE_LIST:
                return (
                    <React.Suspense fallback={fallback}>
                        <ListModal {...props} />
                    </React.Suspense>
                );
            case TYPE_FORM:
                return (
                    <React.Suspense fallback={fallback}>
                        <FormModal {...props} />
                    </React.Suspense>
                );
            case TYPE_LIST_MULTI:
                return (
                    <React.Suspense fallback={fallback}>
                        <ListMultiModal {...props} />
                    </React.Suspense>
                );
            default:
                return null;
        }
    })
);

And this is how it is passed:

const openListModal = (Component, componentProps) => openModal(Component, componentProps, TYPE_LIST);

Anyone with deeper understanding what could possibly cause this?

1 Answer 1

5

Found out by trial by error. It was caused by immer's produce function which builds read-only deep copy of object.

    setModalList(
        produce(modalList, (modalList) => {
            modalList.push({ Component, componentProps, type, show: true });
        })
    );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.