NGRX Store: Unable to modify the immutable property '18' of the object '[object Array]'

While attempting to set up an ngrx store, I encountered 7 errors.

Error Messages: TypeError: Cannot assign to read only property '18' of object '[object Array]' | TypeError: Cannot assign to read only property 'incompleteFirstPass' of object '[object Object]' | TypeError: Cannot read properties of undefined (reading 'value')

reducer.ts

import { createReducer, on } from '@ngrx/store';
import { Fields } from '../fields.model';

import { addAllFields } from './fields.action';

export const initialState: Readonly<Fields> = {
  arrStart: [],
  arrEnd: [],
};

export const fieldsReducer = createReducer(
  initialState,
  on(addAllFields, (state, { extArr }) => {
    return { ...state, arrStart: extArr };
  })
);

actions.ts

import { TemplateRef } from '@angular/core';
import { createAction, props } from '@ngrx/store';

export const addAllFields = createAction(
  '[Fields Array]Add fields to starting array',
  props<{ extArr: TemplateRef<any>[] }>()
);

fields.model.ts

import { TemplateRef } from '@angular/core';

export interface Fields {
  arrStart: TemplateRef<any>[] | null;
  arrEnd: TemplateRef<any>[] | null;
}

I understand the importance of state immutability, hence why I return a copy of my current state.

The issue may lie in the dispatch function within my component. Upon running console.log(fieldsArr), it returns 2 TemplateRef

constructor(private store: Store) {}

  ngOnInit(): void {}

  ngAfterViewInit() {
    const fieldsArr: TemplateRef<any>[] = [this.inputField, this.textareaField];
    console.log(fieldsArr);

    this.store.dispatch(addAllFields({ extArr: fieldsArr }));
  }

Answer №1

The issue might lie with the TemplateRef. It seems that when these are sent to the store, they become immutable. My theory is that Angular manipulates the TemplateRef during change detection, leading to conflicts with the frozen instance in the store and resulting in this error.

Answer №2

In order to prevent mutations to TemplateRef within NGRX, you can adjust the configuration settings as shown below:

StoreModule.forRoot({}, {
                runtimeChecks: {
                  strictStateImmutability: false,
                  strictActionImmutability: false,
   
                }
              }),

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The error occurred in async JavaScript parallel code because the task is not recognized as a function

I am attempting to upload an image and update the image URL in the database collection using the code provided below. Controller.prototype.handle = function (req, res, next) { var id = req.params.id, controller = req.params.controller, optio ...

How can we use the jQuery toggle function to hide and show elements based on

When using the toggle function, I have noticed that it takes a considerable amount of time to load. As a solution, I attempted to include a loading image while the content loads; however, the image does not appear when the .showall is activated. This iss ...

Is there a way to sort through nested objects with unspecified keys?

I'm looking to extract specific information from a nested object with unknown keys and create a new array with it. This data is retrieved from the CUPS API, where printer names act as keys. I want to filter based on conditions like 'printer-stat ...

Issues encountered when using PrimeNG tree select component with filter functionality

After successfully implementing the new primeng treeselect component with selection mode as "checkbox," I encountered an issue when trying to add a [filter]="true" as shown in the PrimeNG demo. <p-treeSelect [(ngModel)]="selectedNode1" [options]="nodes1 ...

Is there a way to insert a Highchart Image into a spreadsheet in Excel?

Struggling to insert a Highchart's chart image into an Excel file? The goal is to utilize the current "Export Excel" button on a website to export a static image of the Highchart displayed on the webpage directly into an excel spreadsheet. Provided be ...

Setting up jade includes with gulp-jade: A comprehensive guide

Struggling with setting up Jade includes in your gulpfile.js while using gulp-jade? Check out this link for more information. Below is a snippet from the gulpfile.js: var gulp = require('gulp'); var browserSync = require('browser-s ...

Exporting SVG to image in Ionic is successful on Android devices, but the image gets cut off when viewed on

I am facing an issue with exporting an SVG as a base64 encoded image and sending it to the server for storage on Google Cloud Storage. The process works fine on Android and in browsers, but fails when attempted on a physical device running IOS. On IOS, t ...

How can a personalized greeting be added in Node.js to welcome a user by their first name retrieved from a MongoDB database upon logging in?

I am looking to create a login and signup form using React that will allow users to input their name, email, and password. After submission, I want the next page to be a personalized congratulations page with the user's name dynamically inserted. Can ...

What could be causing this excessive lag?

I've been developing a new website, but the "buttons" I'm using seem to be causing significant lag. I need help resolving this issue. You can view the website here: The problematic code snippet is shown below: <td> <a href="templi ...

Utilizing string to access property

Is there a better way to access interface/class properties using strings? Consider the following interface: interface Type { nestedProperty: { a: number b: number } } I want to set nested properties using array iteration: let myType: Type = ...

Creating a dynamic drop-down menu using a single database table in CodeIgniter

Table https://i.sstatic.net/yw7d0.jpg I need the district names to dynamically change based on the Category selection. For example, when I select Category 1 from the drop-down, only the district names under Category 1 should be displayed, and the same fo ...

Unexpected outcomes from the Jquery contains method

Take a look at this example: http://jsfiddle.net/SsPqS/ In my HTML, there's a div with the class "record" to which I've added a click function. Within the click function, I have the following code snippet (simplified): $(".record").click(funct ...

Is there a way to cancel an AJAX request during the ajaxStart or ajaxSend event in jQuery?

In my project, I have implemented numerous $.post methods and now I need to check the session in each request to handle my page based on session value. However, I don't want to modify all the existing methods ($.post). Instead, I would like to check t ...

The method `this.http.post(...).map` is not recognized as a valid function

doSelectMessagesAttributesUrl1(pushRequest : PushRequest) { console.info("sending post request"); let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded'}); return this.http .post(th ...

Leveraging ng-change in AngularJS when utilizing the "Controller As" syntax

Attempting to steer clear of using $scope within my controller function, I have instead chosen to use var viewModel = this; employing the "controller as" viewModel syntax. The issue at hand is that while I can access data from a service, invoking functio ...

React Virtualized - Blank screen issue occurring because of continuous scrolling through a large list of ITSM items

I am currently working on a lengthy list of items and utilizing the react-virtualized library for this purpose. However, I have encountered an issue that needs addressing. https://i.stack.imgur.com/ROdjp.gif Upon attempting to scroll down for 2 seconds, ...

Ways to prevent a loop from constantly restarting

After clicking the generate ID button once, it will become disabled and display a set of numbers. The last 4 digits are in a loop sequence starting with "0001". If I were to re-enable the generate ID button and click it again, the last 4 digits would incre ...

Verification for collaborative element

I am currently working on creating a shared component for file uploads that can be reused whenever necessary. Interestingly, when I include the file upload code in the same HTML as the form, the validation functions properly. However, if I extract it into ...

A guide to efficiently removing an element in Angular using TypeScript by considering certain properties

I need help removing an element from an array based on any property such as its key, name, or email. HTML <tr *ngFor="let person of persons;" (click)="remove(person.key)"> <td>{{person.key}}</td> <td>{{person.name}}</td> ...

Delaying the intensive rendering process in Vue.js and Vuetify: A comprehensive guide

Recently, while working on a project with Vue.js 2 and Vuetify 2.6, I encountered an issue with heavy form rendering within expansion panels. There seems to be a slight delay in opening the panel section upon clicking the header, which is most likely due t ...