-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Preview: skip rendering rich text #60544
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ import { getBlockType, store as blocksStore } from '@wordpress/blocks'; | |
*/ | ||
import { useBlockEditorAutocompleteProps } from '../autocomplete'; | ||
import { useBlockEditContext } from '../block-edit'; | ||
import { blockBindingsKey } from '../block-edit/context'; | ||
import { blockBindingsKey, isPreviewModeKey } from '../block-edit/context'; | ||
import FormatToolbarContainer from './format-toolbar-container'; | ||
import { store as blockEditorStore } from '../../store'; | ||
import { useUndoAutomaticChange } from './use-undo-automatic-change'; | ||
|
@@ -44,7 +44,7 @@ import { useInsertReplacementText } from './use-insert-replacement-text'; | |
import { useFirefoxCompat } from './use-firefox-compat'; | ||
import FormatEdit from './format-edit'; | ||
import { getAllowedFormats } from './utils'; | ||
import { Content } from './content'; | ||
import { Content, valueToHTMLString } from './content'; | ||
import { withDeprecations } from './with-deprecations'; | ||
import { unlock } from '../../lock-unlock'; | ||
import { canBindBlock } from '../../hooks/use-bindings-attributes'; | ||
|
@@ -485,6 +485,50 @@ PrivateRichText.isEmpty = ( value ) => { | |
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md | ||
*/ | ||
const PublicForwardedRichTextContainer = forwardRef( ( props, ref ) => { | ||
const context = useBlockEditContext(); | ||
const isPreviewMode = context[ isPreviewModeKey ]; | ||
|
||
if ( isPreviewMode ) { | ||
// Remove all non-content props. | ||
const { | ||
children, | ||
tagName: Tag = 'div', | ||
value, | ||
onChange, | ||
isSelected, | ||
multiline, | ||
inlineToolbar, | ||
wrapperClassName, | ||
autocompleters, | ||
onReplace, | ||
placeholder, | ||
allowedFormats, | ||
withoutInteractiveFormatting, | ||
onRemove, | ||
onMerge, | ||
onSplit, | ||
__unstableOnSplitAtEnd, | ||
__unstableOnSplitAtDoubleLineEnd, | ||
identifier, | ||
preserveWhiteSpace, | ||
__unstablePastePlainText, | ||
__unstableEmbedURLOnPaste, | ||
__unstableDisableFormats, | ||
disableLineBreaks, | ||
__unstableAllowPrefixTransformations, | ||
readOnly, | ||
...contentProps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if using "opt-in" (listing the content props and omitting the rest) is clearer than "opt-out" here. Also why remove "native props" from preview, aren't these "style related" previews that are important for previews? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't do that because we don't know all the possible attributes people could be passing to the tag. I mean, we can't unless we list all possible React props. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok but what about this part "aren't these "style related" previews that are important for previews?" in other words, why are we calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block authors can pass all sorts of attributes to rich text, it's not just styles. Classes, data attributes, and all other valid HTML attribute names. We are removing native props because these are component props, not attribute names, and otherwise React will throw warnings that these aren't valid attribute names when trying to set them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I got confused by the "native" in the function name. I thought it was about removing regular DOM attributes rather than removing "native like mobile native" RichText version attribute. |
||
} = removeNativeProps( props ); | ||
return ( | ||
<Tag | ||
{ ...contentProps } | ||
dangerouslySetInnerHTML={ { | ||
__html: valueToHTMLString( value, multiline ), | ||
} } | ||
/> | ||
); | ||
} | ||
|
||
return <PrivateRichText ref={ ref } { ...props } readOnly={ false } />; | ||
} ); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ellatrix, is the
format
prop used anywhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a very old prop. I believe years ago at the start of GB we had
string
andchildren
. We don't check it anymore, instead we rely on the type of the value (string or array). But we also shouldn't remove this because we'd be spreading it on a plain tag. Maybe it's ok because it's just a React warning in dev mode?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it; it seems fine to keep it around.
There are no warnings. I was looking into React Native code and noticed this prop, but I wasn't sure if it was used anywhere.