refactor(mjml-hero): simplify getChildContext, drop dead width parsing#3104
Open
danfitz36 wants to merge 1 commit into
Open
refactor(mjml-hero): simplify getChildContext, drop dead width parsing#3104danfitz36 wants to merge 1 commit into
danfitz36 wants to merge 1 commit into
Conversation
The child container width was being formatted to a px string and then re-parsed via widthParser, only to branch on whether the unit was %. That branch can never fire because the value is appended with 'px' on the line above. The whole sequence collapses to a single subtraction of the horizontal padding from the parent container width. Also removes the now-unused widthParser import and a stale TODO comment that referenced this code. Adds a regression test covering the inner outlook table width for several padding shorthands; mj-hero had no direct test coverage before. Fix mjmlio#2441.
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.
Fixes #2441.
MjHero.getChildContextwas converting the parent container width to apxstring and then re-parsing it withwidthParserto branch on the unit — but theif (unit === '%')branch can never fire, because the value is appended with'px'on the line above. The whole sequence collapses to a single subtraction.As @iRyusa noted on the issue, the parsing was a remnant of an earlier attempt to support a
widthattribute onmj-heroand is no longer needed.Changes
packages/mjml-hero/src/index.jsif (unit === '%')branch with a directparseFloat(containerWidth) - paddingSizesubtractionwidthParserimport// Refactor -- removePaddingFor(...)TODO commentpackages/mjml/test/hero-padding-inner-width.test.js(new)containerWidth − horizontalPaddingfor a range of padding shorthands.mj-heropreviously had no direct test coverage.Verification