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

guard against undefined value for field #517

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ericbiewener
Copy link

Fixes #503

@@ -25,13 +25,13 @@ export class MyEditorSelection {
}

export function getEditorFromState(state: EditorState) {
const { editor } = state.field(editorInfoField);
const field = state.field(editorInfoField);
Copy link
Author

Choose a reason for hiding this comment

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

My fix just ignorantly addresses the immediate error that is being thrown. But perhaps there is a deeper bug that should prevent the visible error from being possible? The codemirror docs indicate that field() should throw an error if the requested field doesn't exist on the state. Since state.field() is not throwing the error, I assume that the field does exist on the state but its value is undefined. Perhaps this is an unexpected state?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, this fix will hide the error. However, as noted, it does have the potential to cause problems in other areas. It's better to find out why the editor is inaccessible here, and find a reliable way to access it in this context.

Copy link
Author

Choose a reason for hiding this comment

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

That makes sense, although it seems like that logic should be in place for the subsequent conditional check that can return null, no?

Anyway, feel free to just close this PR if it's not the fix you're looking for. Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] TypeError: Cannot read properties of undefined (reading 'editor')
2 participants