Fix editor lifecycle bugs in EmailEditor#480
Open
farhan523 wants to merge 2 commits into
Open
Conversation
- The unmount cleanup captured `editor` from the first render (always
null), so unlayer editors were never destroyed on unmount. Track the
latest instance in a ref so cleanup destroys the real editor.
- The event-listener effect depended on Object.keys(methodProps) which
yields array indices ("0,1,2"), not prop names, so swapping one on*
prop for another was not detected. Use methodProps.join(',') instead.
Adds a regression test that mounts and unmounts the editor with a
mocked embed script and asserts destroy() is called.
5104c5e to
da000bc
Compare
Covers the scenario from unlayer#272: a component that is mounted and unmounted quickly, with the embed script finishing its load afterwards. Asserts no editor is created for the unmounted component and the late script callback does not throw.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two small bug fixes in the React wrapper's lifecycle handling:
1. Editor was never destroyed on unmount
The unmount cleanup in
EmailEditor.tsxclosed overeditorfrom the first render, which is alwaysnull:So
destroy()was a silent no-op and every unmounted editor instance leaked (related: #272). Fixed by tracking the latest instance in a ref. Added a regression test that mounts/unmounts the editor with a mocked embed script and assertsdestroy()is called — it fails on the old code and passes with the fix.2. Broken effect dependency for event-listener props
The event-listener effect depended on
Object.keys(methodProps).join(','), butmethodPropsis an array, so this yields index strings ("0,1,2") rather than prop names. Swapping oneon*prop for another (same count) was invisible to React. Changed tomethodProps.join(','), which is clearly what was intended.Testing
tsdx test— passes, including two new regression tests:tsdx build— compiles cleanlytsdx lint— no new problems introduced (one pre-existing warning removed)