Skip to content

Fix mj-wrapper children disappearing after a child is added or removed - #442

Open
RaphaelFakhri wants to merge 1 commit into
GrapesJS:masterfrom
RaphaelFakhri:fix/wrapper-children-rerender
Open

RaphaelFakhri wants to merge 1 commit into
GrapesJS:masterfrom
RaphaelFakhri:fix/wrapper-children-rerender

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Fixes #385

Problem

After you add or remove a section inside an mj-wrapper, changing any wrapper property (for example, the background color) removes every child section from the canvas. The components stay in the model, so the export is correct, but the editor shows an empty wrapper.

Cause

The wrapper listens to add remove on its components and calls renderChildren() directly. renderChildren() moves the child elements into the container and leaves this.childNodes pointing at the now-empty childNodes list of the children view. render() refreshes this.childNodes after renderChildren(), but the listener does not. The next rerender() (triggered by change:attributes) replaces the wrapper HTML and moves the nodes in this.childNodes into the new container, which is an empty list.

Fix

After the listener renders the children, store the container childNodes, the same way render() does.

Tests

tests/specs/wrapper.test.ts covers both the remove and the add case: it changes a wrapper attribute and checks that the remaining section elements are still rendered inside the wrapper. Both tests fail without the fix and pass with it. The full suite (36 tests), npm run lint, and npm run typecheck pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Wrapper component breaks when property is changed after deleting child section

1 participant