Skip to content

fix(BDropdown): prevent hydration warning in nuxt production mode #2768

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

Merged

Conversation

sebbayer
Copy link
Contributor

@sebbayer sebbayer commented Jul 3, 2025

Describe the PR

Fixes #2763

Small replication

A small replication or video walkthrough can help demonstrate the changes made. This is optional, but can help observe the intended changes. A mentioned issue that contains a replication also works.

PR checklist

What kind of change does this PR introduce? (check at least one)

  • Bugfix 🐛 - fix(...)
  • Feature - feat(...)
  • ARIA accessibility - fix(...)
  • Documentation update - docs(...)
  • Other (please describe)

The PR fulfills these requirements:

  • Pull request title and all commits follow the Conventional Commits convention or has an override in this pull request body This is very important, as the CHANGELOG is generated from these messages, and determines the next version type. Pull requests that do not follow conventional commits or do not have an override will be denied

Summary by CodeRabbit

  • Refactor
    • Improved the way dropdown menu visibility is handled by consolidating display styles into a dynamic style binding, ensuring the menu's display property updates based on its visibility state. No changes to user-facing behavior.

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

coderabbitai bot commented Jul 3, 2025

Walkthrough

The change updates the style binding for the dropdown menu in the BDropdown.vue component. It removes a static display style and replaces it with a dynamic style object that sets display based on the dropdown's visibility state, consolidating all style logic into the reactive binding.

Changes

File(s) Change Summary
packages/bootstrap-vue-next/src/components/BDropdown/BDropdown.vue Refactored dropdown menu <ul> style binding to use a dynamic display property based on showRef; removed static style="display: block" attribute.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BDropdown
    User->>BDropdown: Toggle dropdown
    BDropdown->>BDropdown: Update showRef
    BDropdown->>BDropdown: Recompute style binding (display: block/none)
    BDropdown->>User: Render dropdown menu with correct display style
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix hydration warning in Nuxt production mode for BDropdown by ensuring display style matches SSR/CSR (#2763)

Poem

Oh dropdown, you now appear just right,
No mismatch warnings late at night!
With styles now bound to your toggle state,
Hydration woes evaporate.
A bunny hops with glee,
For Vue and Nuxt in harmony!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
packages/bootstrap-vue-next/src/components/BDropdown/BDropdown.vue (1)

53-58: Remove hardcoded style="display: block" from BToast.vue & BModal.vue

We’ve located two remaining instances of a static style="display: block" that must be updated to the reactive pattern used in BDropdown:

• packages/bootstrap-vue-next/src/components/BToast/BToast.vue (line 14)
• packages/bootstrap-vue-next/src/components/BModal/BModal.vue (line 27)

In each template, replace the literal style="display: block" with a dynamic approach—e.g.:

<!-- before -->
<divstyle="display: block">

<!-- after -->
<div
  v-show="showRef"
  :style="[baseStyles, { display: showRef ? 'block' : 'none' }]"
>

Adjust the prop or ref name (showRef/visible) and any existing style bindings to match each component’s API.

🧹 Nitpick comments (1)
packages/bootstrap-vue-next/src/components/BDropdown/BDropdown.vue (1)

53-58: Consider eliminating the duplicated display-toggle logic.

v-show already sets/clears element.style.display on the same reactive flag (showRef). Keeping an explicit {display: …} object means two separate mechanisms write the same CSS property each update. While harmless today, it is a second source of truth that can drift if one side changes.

Option A (preferred): drop the inline display object and rely solely on v-show.

-:style="[floatingStyles, sizeStyles, {display: showRef ? 'block' : 'none'}]"
+:style="[floatingStyles, sizeStyles]"

Option B: if the explicit display inline style is required for SSR, drop the v-show and keep the object.

Either way keeps one writer for display, simplifying future maintenance.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02be37d and 67472be.

📒 Files selected for processing (1)
  • packages/bootstrap-vue-next/src/components/BDropdown/BDropdown.vue (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: unstoppablecarl
PR: bootstrap-vue-next/bootstrap-vue-next#2671
File: packages/bootstrap-vue-next/src/components/BToast/_toast.scss:1-3
Timestamp: 2025-04-27T17:30:42.045Z
Learning: In global SCSS files for bootstrap-vue-next, `:deep()` combinator should not be used as it only works in Vue's scoped style blocks. Standard CSS/SCSS selectors should be used instead.
Learnt from: xvaara
PR: bootstrap-vue-next/bootstrap-vue-next#2716
File: packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue:240-261
Timestamp: 2025-05-28T07:01:55.095Z
Learning: In BTabs component (packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue), the complex initialization logic with updateInitialActiveIndex and updateInitialActiveId flags is necessary for SSR compatibility. Tab initialization cannot be deferred to mounted lifecycle because tabs must be available for server-side rendering of the initial HTML state.
Learnt from: xvaara
PR: bootstrap-vue-next/bootstrap-vue-next#2716
File: packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue:425-430
Timestamp: 2025-05-28T07:32:45.658Z
Learning: In BTabs component (packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue), the activeIndex synchronization within sortTabs() is necessary and correct. When sorting tabs by DOM position, indices change, so activeIndex must be updated immediately to maintain consistency with activeId. This is not an unwanted side effect but a required consequence of the sorting operation.
packages/bootstrap-vue-next/src/components/BDropdown/BDropdown.vue (4)
Learnt from: unstoppablecarl
PR: bootstrap-vue-next/bootstrap-vue-next#2671
File: packages/bootstrap-vue-next/src/components/BToast/_toast.scss:1-3
Timestamp: 2025-04-27T17:30:42.045Z
Learning: In global SCSS files for bootstrap-vue-next, `:deep()` combinator should not be used as it only works in Vue's scoped style blocks. Standard CSS/SCSS selectors should be used instead.
Learnt from: xvaara
PR: bootstrap-vue-next/bootstrap-vue-next#2716
File: packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue:240-261
Timestamp: 2025-05-28T07:01:55.095Z
Learning: In BTabs component (packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue), the complex initialization logic with updateInitialActiveIndex and updateInitialActiveId flags is necessary for SSR compatibility. Tab initialization cannot be deferred to mounted lifecycle because tabs must be available for server-side rendering of the initial HTML state.
Learnt from: xvaara
PR: bootstrap-vue-next/bootstrap-vue-next#2716
File: packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue:425-430
Timestamp: 2025-05-28T07:32:45.658Z
Learning: In BTabs component (packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue), the activeIndex synchronization within sortTabs() is necessary and correct. When sorting tabs by DOM position, indices change, so activeIndex must be updated immediately to maintain consistency with activeId. This is not an unwanted side effect but a required consequence of the sorting operation.
Learnt from: dwgray
PR: bootstrap-vue-next/bootstrap-vue-next#2701
File: apps/docs/src/docs/migration-guide.md:630-632
Timestamp: 2025-05-23T23:58:07.165Z
Learning: The `<NotYetImplemented/>` component in the bootstrap-vue-next documentation automatically renders text indicating "Not Yet Implemented", so additional explanatory text about features not being implemented is redundant when this component is used.
🔇 Additional comments (1)
packages/bootstrap-vue-next/src/components/BDropdown/BDropdown.vue (1)

53-58: Hydration fix makes sense – LGTM.

Moving display into the reactive :style binding eliminates the static style="display: block" that caused the SSR/client mismatch. This should silence Nuxt’s hydration warning.

Copy link

pkg-pr-new bot commented Jul 7, 2025

bsvn-vite-ts

npm i https://pkg.pr.new/bootstrap-vue-next/bootstrap-vue-next@2768
npm i https://pkg.pr.new/bootstrap-vue-next/bootstrap-vue-next/@bootstrap-vue-next/nuxt@2768

commit: 67472be

@VividLemon VividLemon merged commit 62e0632 into bootstrap-vue-next:main Jul 7, 2025
5 checks passed
@github-actions github-actions bot mentioned this pull request Jul 7, 2025
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.

BDropdown hydration warning in Nuxt production mode
2 participants