Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Actually for real fix the flow type of decorator props
Browse files Browse the repository at this point in the history
Summary:
The 'entityKey' could always have been null/undefined, and it's time that the
flow type reflects that. Our code should handle the case, though unexpected,
when it could be undefined.

A previous diff[1] was submitted but somehow the changes were not all commited.
This finishes the job, updating decorator components in our product code and the
type definition in Draft.js.

[1]: https://our.intern.facebook.com/intern/diff/D7659273/

Reviewed By: sophiebits

Differential Revision: D7710224

fbshipit-source-id: 7c673a565f79e45bced91db5b406974f9813327d
  • Loading branch information
flarnie authored and facebook-github-bot committed Apr 26, 2018
1 parent 05b2b4c commit 7e1a107
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/component/contents/DraftEditorBlock.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ class DraftEditorBlock extends React.Component<Props> {
start,
end,
blockKey,
// $FlowFixMe
entityKey,
offsetKey: decoratorOffsetKey,
};
Expand Down
11 changes: 10 additions & 1 deletion src/model/decorators/DraftDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ export type DraftDecoratorComponentProps = {
decoratedText: string,
dir: ?HTMLDir,
end: number,
entityKey: string,

// Many folks mistakenly assume that there will always be an 'entityKey'
// passed to a DecoratorComponent.
// To find the `entityKey`, Draft calls
// `contentBlock.getEntityKeyAt(leafNode)` and in many cases the leafNode does
// not have an entityKey. In those cases the entityKey will be null or
// undefined. That's why `getEntityKeyAt()` is typed to return `?string`.
// See https://github.com/facebook/draft-js/blob/2da3dcb1c4c106d1b2a0f07b3d0275b8d724e777/src/model/immutable/BlockNode.js#L51
entityKey: ?string,

key: React.Key,
offsetKey: string,
start: number,
Expand Down

0 comments on commit 7e1a107

Please sign in to comment.