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

Cover Text Block: Prevent class=false when serializing the block #2363

Merged
merged 2 commits into from
Aug 11, 2017

Conversation

youknowriad
Copy link
Contributor

Props @aduth for catching that. The Cover Text block was serializing class="false" with default Attributes which was causing the "externally modified content" message.

@youknowriad youknowriad added the [Type] Bug An existing feature does not function as intended label Aug 11, 2017
@youknowriad youknowriad self-assigned this Aug 11, 2017
@youknowriad youknowriad requested a review from aduth August 11, 2017 12:49
@codecov
Copy link

codecov bot commented Aug 11, 2017

Codecov Report

Merging #2363 into master will increase coverage by 1.16%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2363      +/-   ##
==========================================
+ Coverage   24.95%   26.11%   +1.16%     
==========================================
  Files         153      156       +3     
  Lines        4780     5157     +377     
  Branches      803      906     +103     
==========================================
+ Hits         1193     1347     +154     
- Misses       3032     3179     +147     
- Partials      555      631      +76
Impacted Files Coverage Δ
blocks/library/table/index.js 36.36% <ø> (ø) ⬆️
blocks/library/paragraph/index.js 47.05% <ø> (ø) ⬆️
blocks/library/image/index.js 16.43% <ø> (+4.19%) ⬆️
blocks/library/embed/index.js 52.02% <100%> (+6.57%) ⬆️
blocks/library/cover-text/index.js 35% <100%> (ø) ⬆️
components/button/index.js 90% <0%> (-0.91%) ⬇️
editor/modes/visual-editor/block.js 0% <0%> (ø) ⬆️
...ditor/modes/visual-editor/invalid-block-warning.js 0% <0%> (ø) ⬆️
editor/index.js 0% <0%> (ø) ⬆️
components/icon-button/index.js 100% <0%> (ø) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0714e2...2973409. Read the comment docs.

@aduth
Copy link
Member

aduth commented Aug 11, 2017

This looks good, and we ought to do an audit of class name assignments like this, since I was able to confirm in minimal case that ReactDOMServer with stringify with false verbatim:

> const React = require( 'React' );
undefined
> const e = React.createElement;
undefined
> const ReactDOMServer = require( 'react-dom/server' );
undefined
> ReactDOMServer.renderToStaticMarkup( e( 'div', { className: false }, 'hello world' ) );
'<div class="false">hello world</div>'

There's another just one line below the one changed here.

@aduth
Copy link
Member

aduth commented Aug 11, 2017

It's primarily an issue in cases where the falsey value is false or 0. undefined or null will avoid assigning the class name.

Alternatively, we can encourage classnames, which handles this well:

> const classnames = require( 'classnames' );
undefined
> classnames( 'foo', false, 'bar', 0, 'baz' );
'foo bar baz'

@youknowriad youknowriad merged commit a7f062c into master Aug 11, 2017
@youknowriad youknowriad deleted the fix/cover-text-serialization branch August 11, 2017 16:04
ceyhun pushed a commit that referenced this pull request Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants