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

docs(adr): add development-warnings adr #2928

Merged
merged 4 commits into from
Mar 1, 2023
Merged

Conversation

joshblack
Copy link
Member

@joshblack joshblack commented Feb 22, 2023

ADR for Development Warnings in @primer/react

Rendered markdown

Pull Request

@joshblack joshblack requested review from a team and langermank February 22, 2023 17:50
@changeset-bot
Copy link

changeset-bot bot commented Feb 22, 2023

⚠️ No Changeset found

Latest commit: 7e42365

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@joshblack joshblack added the skip changeset This change does not need a changelog label Feb 22, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 22, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 94.49 KB (0%)
dist/browser.umd.js 95.07 KB (0%)

@joshblack joshblack temporarily deployed to github-pages February 22, 2023 17:55 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2928 February 22, 2023 17:56 Inactive
Copy link
Contributor

@mperrotti mperrotti left a comment

Choose a reason for hiding this comment

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

I like this direction! Once this merges, could we create an issue to implement the warning() helper?

@joshblack joshblack temporarily deployed to github-pages February 22, 2023 18:10 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2928 February 22, 2023 18:11 Inactive
should use the `warning()` helper.

```ts
warning(condition, 'This is the message that is logged when condition is false-y')
Copy link
Contributor

@colebemis colebemis Feb 22, 2023

Choose a reason for hiding this comment

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

I would have guessed that the message would display if the condition is truthy. I read that code as "warn if condition"

If this is a convention, I'm fine to keep it. But I wanted to mention my initial confusion.

If the name of the helper was something like assert(), I think falsey would make more sense.

Copy link
Member

Choose a reason for hiding this comment

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

I would have guessed that the message would display if the condition is truthy. I read that code as "warn if condition"

Ohh, this is how I think it was as well the entire time - now realised that 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally makes sense! Happy to flip it if that's more intuitive for folks 👍

I think the convention stems from invariant() ultimately, and things like assert(), that frame things from the perspective of "this condition must be met". When it's not met, throw an error, log a warning, etc

To contextualize the two, here is the warning from Heading in the two styles:

// Warn if condition is true
warning(
  innerRef.current && !(innerRef.current instanceof HTMLHeadingElement),
  'This Heading component should be an instanceof of h1-h6'
);
// Warn if condition is false
warning(
  innerRef.current && innerRef.current instanceof HTMLHeadingElement,
  'This Heading component should be an instanceof of h1-h6'
);

Copy link
Member

Choose a reason for hiding this comment

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

Thanks Josh! Warning when the condition truthy feels more intuitive to me. That said, it is totally cool to me if we want follow the convention that it stems from.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's do truth-y then! I'll update the ADR accordingly 👍

@joshblack

This comment was marked as outdated.

@lesliecdubs
Copy link
Member

@joshblack so far it seems most folks are in alignment here, but if you'd like me to assign a decision-maker on this one give me a shout.

@github-actions github-actions bot temporarily deployed to storybook-preview-2928 February 28, 2023 16:23 Inactive
@joshblack joshblack added this pull request to the merge queue Mar 1, 2023
Merged via the queue into main with commit 87c999f Mar 1, 2023
@joshblack joshblack deleted the docs/add-console-warn-adr branch March 1, 2023 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip changeset This change does not need a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants