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

Throw error when resolver is not an object + Better error messages when deserializing unknown nodes #133

Merged
merged 12 commits into from
Nov 5, 2020

Conversation

ankri
Copy link
Collaborator

@ankri ankri commented Nov 3, 2020

Yay I'm back. With a smaller change this time.

This should help to prevent some common beginner mistakes.

Display an error when resolver on <Editor /> is not an object

image

Display an error which component cannot be resolved

image

@ankri ankri requested a review from prevwong as a code owner November 3, 2020 11:58
@netlify
Copy link

netlify bot commented Nov 3, 2020

Deploy preview for craftjs ready!

Built with commit 4b199c0

https://deploy-preview-133--craftjs.netlify.app

@ankri
Copy link
Collaborator Author

ankri commented Nov 5, 2020

I replaced RTL with enzyme. 👍

Copy link
Owner

@prevwong prevwong left a comment

Choose a reason for hiding this comment

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

Welcome back! Looks good, just 1 tiny suggestion!

Comment on lines 77 to 84
invariant(
(Comp !== undefined && typeof Comp === 'string' && Comp.length > 0) ||
(Comp as { resolvedName?: string }).resolvedName !== undefined,
ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER.replace(
'%displayName%',
data.displayName
).replace('%availableComponents%', Object.keys(resolver).join(', '))
);
Copy link
Owner

Choose a reason for hiding this comment

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

Can we break this line up so it is more readable?

Ie:

Suggested change
invariant(
(Comp !== undefined && typeof Comp === 'string' && Comp.length > 0) ||
(Comp as { resolvedName?: string }).resolvedName !== undefined,
ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER.replace(
'%displayName%',
data.displayName
).replace('%availableComponents%', Object.keys(resolver).join(', '))
);
const isCompHtmlElement = Comp !== undefined && typeof Comp === 'string';
const isCompUserComponent = Comp !== undefined && (Comp as { resolvedName?: string }).resolvedName !== undefined;
invariant(isCompHtmlElement || isCompUserComponent, '....')

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea, done

@prevwong prevwong merged commit be0ee35 into prevwong:develop Nov 5, 2020
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.

2 participants