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

Fix block error when transforming blocks with Link Popover opened #28136

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/rich-text/src/component/use-anchor-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export function useAnchorRef( { ref, value, settings = {} } ) {
const activeFormat = name ? getActiveFormat( value, name ) : undefined;

return useMemo( () => {
const { ownerDocument } = ref.current;
const { defaultView } = ownerDocument;
if ( ! ref.current ) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this null? On first render?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like rewriting as a callback ref would fix it, this is typically the kind of bugs passing "ref" to hooks can create.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just a small remark, not necessarily for now)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It's undefined when clicking the transform item.

const {
ownerDocument: { defaultView },
} = ref.current;
const selection = defaultView.getSelection();

if ( ! selection.rangeCount ) {
Expand Down