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

Update TableComponent.tsx to use deepClone function over spread. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update TableComponent.tsx to use deepClone function instead of spre…
…ad syntax

When using the table within a block editor, having created a table, left the document and returned, adding a new row/s would result in an 'can't define property "x": "obj" is not extensible' error in the console.

Both the `addRows` and `addRowAt` functions were using spread syntax when assigning the `newValue` const, rather than using the `deepClone` function which is used by all other functions, which resulted in the error.
bendesilva committed Feb 25, 2022
commit d75a40c77f78656ffc147979e65d497933d4f58a
4 changes: 2 additions & 2 deletions src/TableComponent.tsx
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ const TableComponent: FunctionComponent<RootProps> = (props) => {
};

const addRows = (count: number = 1) => {
const newValue = { ...value };
const newValue = deepClone(value);
// Calculate the column count from the first row
const columnCount = value.rows[0].cells.length;
for (let i = 0; i < count; i++) {
@@ -71,7 +71,7 @@ const TableComponent: FunctionComponent<RootProps> = (props) => {
};

const addRowAt = (index: number = 0) => {
const newValue = { ...value };
const newValue = deepClone(value);
// Calculate the column count from the first row
const columnCount = value.rows[0].cells.length;