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: BNavbar crash with "TypeError: this.$slots.brand is not a function" (#28) #30

Merged
merged 2 commits into from
Aug 22, 2023

Conversation

kikuomax
Copy link
Collaborator

Fixes:

Proposed Changes

  • Check if this.$slots.brand is not nullish before calling it

- Fixes the bug where an empty `BNavbar` crashed with "TypeError:
  this.$slots.brand is not a function". Checks if `this.$slots.brand` is
  not nullish before calling it.

issue ntohq#28
@kikuomax kikuomax requested a review from wesdevpro August 14, 2023 02:40
@@ -168,10 +168,16 @@ export default {
])
},
genNavbarBrandNode() {
let children

Choose a reason for hiding this comment

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

Semicolon?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does this look better?

const children = this.$slots.brand != null
    ? [this.$slots.brand(), this.genBurgerNode()]
    : this.genBurgerNode()

Choose a reason for hiding this comment

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

Yes that works ✨

Copy link

@wesdevpro wesdevpro Aug 16, 2023

Choose a reason for hiding this comment

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

You can also add parentheses to make the conditional expression more clear in the ternary operation

const children = (this.$slots.brand != null) 
       ? [this.$slots.brand(), this.genBurgerNode()] 
       : this.genBurgerNode()

src/components/navbar/Navbar.vue Outdated Show resolved Hide resolved
@@ -168,10 +168,16 @@ export default {
])
},
genNavbarBrandNode() {
let children

Choose a reason for hiding this comment

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

Yes that works ✨

@@ -168,10 +168,16 @@ export default {
])
},
genNavbarBrandNode() {
let children
Copy link

@wesdevpro wesdevpro Aug 16, 2023

Choose a reason for hiding this comment

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

You can also add parentheses to make the conditional expression more clear in the ternary operation

const children = (this.$slots.brand != null) 
       ? [this.$slots.brand(), this.genBurgerNode()] 
       : this.genBurgerNode()

@@ -168,10 +168,13 @@ export default {
])
},
genNavbarBrandNode() {
const children = this.$slots.brand != null
? [this.$slots.brand(), this.genBurgerNode()]
: this.genBurgerNode()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@wesdevpro I believe the updated code is legible enough and aligns with the style of the other part of the codebase.

Choose a reason for hiding this comment

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

Looks good ✨

@wesdevpro
Copy link

@kikuomax please pull the changes into dev. For some reason I can't create a merge and commit.

@kikuomax kikuomax merged commit 1badbc8 into ntohq:dev Aug 22, 2023
@kikuomax kikuomax deleted the fix-navbar-crash branch August 22, 2023 01:24
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