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

🐛 [bento][amp-social-share] Preact component should not throw error #30200

Merged
merged 8 commits into from
Sep 23, 2020

Conversation

krdwan
Copy link
Contributor

@krdwan krdwan commented Sep 11, 2020

Tracking Issue: #28283

Updated Preact component and automated tests for Social Share.

Preact component should not throw an error.

@@ -54,31 +54,34 @@ export function SocialShare({
checkedWidth,
checkedHeight,
checkedTarget,
errorState,
Copy link
Contributor

Choose a reason for hiding this comment

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

Per discussion. I don't think we need to track errorState. We need to simplify it to a point of almost no error processing done in a component. The most important consequence is that we likely need to drop tests with expect(() => mount(jsx)).to.throw.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @dvoytenko . Updated revision is up. I still included some minimal error checking which results in the component immediately returning null and does not render anything.

The corresponding tests check for an empty render instead of an error being thrown.

I have included a console.warn to notify the publisher and check for this in the tests. These can be removed if you think it makes more sense. Thanks!!


it('warns when the required "type" attribute is not provided', () => {
const consoleOutput = [];
const mockedWarn = (output) => consoleOutput.push(output);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use allowConsoleError.

if (type === undefined) {
throw new Error(`The type attribute is required. ${NAME}`);
displayWarning(`The type attribute is required. ${NAME}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed. Let's update type.

`An endpoint is required if not using a pre-configured type. ${NAME}`
);
return {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we return null instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks updated!

Copy link
Contributor

@dvoytenko dvoytenko left a comment

Choose a reason for hiding this comment

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

LGTM with one nit.

@@ -120,27 +134,23 @@ function processChildren(type, children, color, background, size) {
* @param {number|string|undefined} width
* @param {number|string|undefined} height
* @param {JsonObject|Object|undefined} params
* @return {{
* @return {null|{
Copy link
Contributor

Choose a reason for hiding this comment

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

Just {?{...}}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks updated!

@@ -18,7 +18,7 @@

/**
* @typedef {{
* type: (string|undefined),
* type: (!string),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dvoytenko I updated this to non-nullable string. Is this what you meant by strict string?

Copy link
Contributor

Choose a reason for hiding this comment

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

Strict string is just string. I.e. no ? or |null or |undefined or any other |. The ! is not needed for primitive types, and I think the Closure styleguide complains about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks for clarifying!

@krdwan krdwan merged commit aa0804a into ampproject:master Sep 23, 2020
ed-bird pushed a commit to ed-bird/amphtml that referenced this pull request Dec 10, 2020
…mpproject#30200)

* Preact component updated to not throw error

* Cleaner early exit on error for Social Share

* Remove errorState from social share

* checkProps should return null

* Update preact types file to non-nullable string for type prop

* Update syntax for nullable object return type

* Remove test for checking type prop is provided

* Update strict string without ! in social-share.type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants