8000 fix(BTabs): corrent classes on ssr by xvaara · Pull Request #2664 · bootstrap-vue-next/bootstrap-vue-next · GitHub
[go: up one dir, main page]

Skip to content

fix(BTabs): corrent classes on ssr #2664

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
merged 6 commits into from
Apr 30, 2025
Merged

Conversation

xvaara
Copy link
Contributor
@xvaara xvaara commented Apr 17, 2025

fixes #2652

Describe the PR

A clear and concise description of what the pull request does.

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

  • Bug Fixes
    • Improved tab registration and activation timing for more reliable tab behavior.
    • Enhanced fallback logic to render tabs from slot content when internal registration is unavailable.
  • New Features
    • Added a method to explicitly sort tabs, improving tab order consistency.
    • Introduced automatic flattening of nested tab fragments for better tab rendering.
    • Updated tab click handling for improved event processing.
    • Added support for custom navigation item classes on tabs.

Copy link

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

Copy link
coderabbitai bot commented Apr 17, 2025

"""

Walkthrough

The changes update the initialization and tab registration logic in the BTabs and BTab components. In BTab.vue, tab registration and activation are now performed synchronously during setup if the parent context exists, instead of waiting for the onMounted lifecycle. In BTabs.vue, the computed tabs property is enhanced to extract tab information directly from slot content as a fallback when no internal tabs are registered, ensuring tab headers and content are available immediately. Additionally, a new sortTabs method is introduced to explicitly sort tabs by their DOM position and is provided via injection for external use. These modifications alter the control flow to support immediate tab rendering, especially during server-side rendering.

Changes

File(s) Change Summary
packages/bootstrap-vue-next/src/components/BTabs/BTab.vue Removed onMounted wrapper; moved tab registration and activation to run synchronously during setup if parent context exists; added onMounted hook to call parentData.sortTabs() if present.
packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue Refactored tabs computed property to extract tab info from slot content as fallback when no internal tabs registered; introduced sortTabs method to sort tabs by DOM position; provided sortTabs via injection key; modified handleClick to call onClick as a higher-order function.
packages/bootstrap-vue-next/src/utils/keys.ts Extended tabsInjectionKey type definition to include new sortTabs: () => void method signature.
packages/bootstrap-vue-next/src/utils/flattenFragments.ts Added new utility function flattenFragments to recursively flatten Vue Fragment nodes into a single-level array of VNodes.
packages/bootstrap-vue-next/src/types/Tab.ts Changed onClick property type in TabType interface from (event: Event) => void to () => (event: Event) => void; added optional navItemClasses property.

Sequence Diagram(s)

sequenceDiagram
    participant Parent as BTabs
    participant Child as BTab

    Note over Child: Setup phase
    Child->>Parent: Register and activate tab synchronously (if parentData exists)
    Child->>Parent: onMounted calls parentData.sortTabs() (if parentData exists)
    Note over Parent: Compute tabs
    alt Internal tabs registered
        Parent->>Parent: Use tabsInternal.value for tabs
    else No internal tabs
        Parent->>Parent: Extract tab info from slot content fallback
    end
    Parent->>Child: Set active tab state
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure BTabs renders tab headers and active tab content immediately, avoiding CLS during SSR/client mount (#2652)

Poem

A hop and a skip, the tabs now appear,
No waiting for mount, they’re rendered right here!
Headers and content, both show up in sync,
No shifting or flicker, much faster than you think.
With code so refined, our tabs shine anew—
A rabbit’s delight, for both old and new!
🐇✨
"""


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bb34096 and f000250.

📒 Files selected for processing (1)
  • packages/bootstrap-vue-next/src/types/Tab.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bootstrap-vue-next/src/types/Tab.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

@xvaara xvaara requested review from Copilot and VividLemon April 17, 2025 09:46
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

packages/bootstrap-vue-next/src/components/BTabs/BTab.vue:84

  • Moving the tab registration out of the onMounted hook may lead to a timing issue if parentData isn't fully initialized. Consider reverting to using onMounted to ensure the parent's data is available before registration.
if (parentData) {

@xvaara
Copy link
Contributor Author
xvaara commented Apr 17, 2025

@VividLemon the way we register the tabs, they arent there on the first pass so this is kinda a hack to get them working in the setup context for ssr.

Copy link
pkg-pr-new bot commented Apr 17, 2025

bsvn-vite-ts

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

commit: f000250

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: 3

🧹 Nitpick comments (2)
packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue (2)

156-178: Consider in‑place function references for class helpers

titleItemClass, titleLinkAttrs, titleLinkClass are wrapped in arrow functions so the consuming template still calls them with ().
If these props are already functions you could pass them through unchanged to save an indirection:

- titleItemClass: () => tab.props?.titleItemClass,
- titleLinkAttrs: () => tab.props?.titleLinkAttrs,
- titleLinkClass: () => tab.props?.titleLinkClass,
+ titleItemClass: tab.props?.titleItemClass,
+ titleLinkAttrs: tab.props?.titleLinkAttrs,
+ titleLinkClass: tab.props?.titleLinkClass,

Not critical, but it reduces one level of call‑stack noise.


367-368: Injection key updated — document the new contract

The additional sortTabs method is now part of the public injections API.
Please add a brief JSDoc block (or update any existing type definition) so downstream component authors know it exists.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9066acb and 90eab1b.

📒 Files selected for processing (2)
  • packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue (6 hunks)
  • packages/bootstrap-vue-next/src/utils/flattenFragments.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/bootstrap-vue-next/src/utils/flattenFragments.ts
🧰 Additional context used
🪛 GitHub Check: test-lint
packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue

[warning] 147-147:
Unexpected console statement

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (2)
packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue (2)

84-86: 👍 Necessary imports added

flattenFragments and BTab are now brought into scope which makes the SSR‑fallback logic possible. No issues spotted here.


314-315: 👍 Calling findActive() after registration keeps state in sync

Triggering findActive() right after the first sort ensures the correct tab is marked active even during rapid dynamic inserts.

@xvaara xvaara mentioned this pull request Apr 22, 2025
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: 1

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

239-249: 🛠️ Refactor suggestion

Avoid calling onClick() twice & make the flow safer

handleClick() evaluates onClick() once in the guard and a second time for execution.
If the wrapper allocates fresh closures or has side‑effects, this double invocation is undesirable.
Capturing the result once also simplifies the checks:

 const handleClick = (event: Readonly<MouseEvent>, index: number) => {
   activateTab(index)
-  if (
-    index >= 0 &&
-    !tabs.value[index].disabled &&
-    tabs.value[index]?.onClick &&
-    typeof tabs.value[index].onClick === 'function' &&
-    typeof tabs.value[index].onClick() === 'function'
-  ) {
-    tabs.value[index].onClick?.()(event)
-  }
+  if (index < 0) return
+  const tab = tabs.value[index]
+  if (tab.disabled || typeof tab.onClick !== 'function') return
+  const clickHandler = tab.onClick()
+  if (typeof clickHandler === 'function') {
+    clickHandler(event)
+  }
 }
♻️ Duplicate comments (1)
packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue (1)

142-146: ⚠️ Potential issue

filter predicate is still not null‑safe – same crash vector as before

Past feedback already highlighted that flattenFragments can yield undefined entries, yet the predicate still dereferences tab.type unguarded.
A single empty node in the slot will throw at render time (TypeError: Cannot read properties of undefined (reading 'type')).

-  const tabElementsArray = (Array.isArray(tabElements) ? tabElements : [tabElements]).filter(
-    (tab) => tab.type === BTab
-  )
+  const tabElementsArray = (Array.isArray(tabElements) ? tabElements : [tabElements]).filter(
+    (tab) => tab && tab.type === BTab
+  )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90eab1b and bb34096.

📒 Files selected for processing (3)
  • packages/bootstrap-vue-next/src/components/BTabs/BTab.vue (1 hunks)
  • packages/bootstrap-vue-next/src/components/BTabs/BTabs.vue (7 hunks)
  • packages/bootstrap-vue-next/src/types/Tab.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bootstrap-vue-next/src/components/BTabs/BTab.vue
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build

@xvaara
Copy link
Contributor Author
xvaara commented Apr 28, 2025

@VividLemon do you see any other way how we could get the ssr context working? I'm not a fan of using the VNode structure, but I couldn't figure another way to fix this.

@VividLemon
Copy link
Member

@VividLemon do you see any other way how we could get the ssr context working? I'm not a fan of using the VNode structure, but I couldn't figure another way to fix this.

Due to the immense overhead of this component, it would seem better to introduce another library to handle this, like Radix-vue.

@xvaara
Copy link
Contributor Author
xvaara commented Apr 30, 2025

@VividLemon do you see any other way how we could get the ssr context working? I'm not a fan of using the VNode structure, but I couldn't figure another way to fix this.

Due to the immense overhead of this component, it would seem better to introduce another library to handle this, like Radix-vue.

I don't really see how that would make any sense. They have a totally different way of doing tabs, totally different api.
The basic philosophy of bootstrap-vue-next is to to non-verbose and do clever stuff. Reka-ui (new name for Radix-vue) is the opposite, it's very verbose, doesn't do stuff without you defining everything.

And we'd have the same problems with it if we don't change the api (ie. use another component for the tab button, and another for tab content) and leave the problems to the user.

@xvaara xvaara merged commit 2b37c18 into bootstrap-vue-next:main Apr 30, 2025
5 checks passed
@xvaara xvaara deleted the tab-ssr-fix branch April 30, 2025 01:36
@github-actions github-actions bot mentioned this pull request Apr 30, 2025
Merged
xvaara added a commit to xvaara/bootstrap-vue-next that referenced this pull request May 14, 2025
* upstream/main:
  chore: release main (bootstrap-vue-next#2690)
  docs(BProgress): Parity pass (bootstrap-vue-next#2689)
  fix(BTableSimple): fixed and nobordercollapse to work fixes bootstrap-vue-next#2685
  docs: fix incorrect references and missed script sections (bootstrap-vue-next#2686)
  docs: implement on this page expand/collapse with useScrollspy (bootstrap-vue-next#2679)
  chore: release main (bootstrap-vue-next#2683)
  feat(BTable): implement 'fixed' and 'noBorderCollapse' props (bootstrap-vue-next#2681)
  chore: release main (bootstrap-vue-next#2678)
  Update package.json
  fix(BFormSelect): prevent options with label from being treated as groups (bootstrap-vue-next#2666)
  fix: patch regression issue in bootstrap-vue-next#2665 (bootstrap-vue-next#2670)
  Update release-main.yaml
  chore: release main (bootstrap-vue-next#2660)
  chore: update depencies
  fix(BTabs): corrent classes on ssr (bootstrap-vue-next#2664)
  Changes to public composables (bootstrap-vue-next#2425)
  docs(BTable): parity pass (bootstrap-vue-next#2669)
xvaara added a commit to unstoppablecarl/bootstrap-vue-next that referenced this pull request May 22, 2025
fix(BTabs): corrent classes on ssr
fix(BTabs): fix another recursion error
xvaara added a commit to unstoppablecarl/bootstrap-vue-next that referenced this pull request May 22, 2025
commit 2a9e30b
Author: Jukka Raimovaara <roska@mentalhouse.fi>
Date:   Thu May 15 18:24:07 2025 +0300

    doc data

commit 08c89fd
Author: Jukka Raimovaara <roska@mentalhouse.fi>
Date:   Thu May 15 17:57:29 2025 +0300

    feat(BPopover): add titleClass and bodyClass, remove unneeded customClass prop since class is inherited to the same place

commit 90b578d
Author: Jukka Raimovaara <roska@mentalhouse.fi>
Date:   Wed May 14 11:39:42 2025 +0300

    feat(BToast): add noProgress prop, make progress show as default if modelValue is number. fix(useToastController): if using the deprecated show method the countdown didn't start.

commit dc85d94
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Sun May 11 09:53:25 2025 -0500

    chore: release main (bootstrap-vue-next#2690)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

commit 070cb8c
Author: David W. Gray <dwgray67@hotmail.com>
Date:   Sun May 11 07:52:30 2025 -0700

    docs(BProgress): Parity pass (bootstrap-vue-next#2689)

commit c61f532
Author: Thierry Blind <tbl0605@gmail.com>
Date:   Sun May 11 16:52:14 2025 +0200

    fix(BTableSimple): fixed and nobordercollapse to work fixes bootstrap-vue-next#2685

commit beae36f
Author: David W. Gray <dwgray67@hotmail.com>
Date:   Sun May 11 07:43:58 2025 -0700

    docs: fix incorrect references and missed script sections (bootstrap-vue-next#2686)

commit 34432d9
Author: David W. Gray <dwgray67@hotmail.com>
Date:   Sun May 11 07:42:02 2025 -0700

    docs: implement on this page expand/collapse with useScrollspy (bootstrap-vue-next#2679)

commit ce869f0
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Wed May 7 11:16:08 2025 -0500

    chore: release main (bootstrap-vue-next#2683)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

commit 9486276
Author: Mohamed Nasri <51300752+mhn147@users.noreply.github.com>
Date:   Wed May 7 09:44:38 2025 -0600

    feat(BTable): implement 'fixed' and 'noBorderCollapse' props (bootstrap-vue-next#2681)

commit a4a9294
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Mon May 5 09:16:09 2025 -0500

    chore: release main (bootstrap-vue-next#2678)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

commit 0165e94
Author: Jukka Raimovaara <roska@mentalhouse.fi>
Date:   Mon May 5 16:24:04 2025 +0300

    Update package.json

commit c1645a9
Author: Rajitha <rajithaeye@gmail.com>
Date:   Wed Apr 30 23:49:23 2025 +0530

    fix(BFormSelect): prevent options with label from being treated as groups (bootstrap-vue-next#2666)

commit 59ddc39
Author: Thierry Blind <tbl0605@gmail.com>
Date:   Wed Apr 30 20:17:34 2025 +0200

    fix: patch regression issue in bootstrap-vue-next#2665 (bootstrap-vue-next#2670)

commit d82091b
Author: Jukka Raimovaara <roska@mentalhouse.fi>
Date:   Wed Apr 30 06:01:10 2025 +0300

    Update release-main.yaml

commit 31cb4bf
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Wed Apr 30 04:51:31 2025 +0300

    chore: release main (bootstrap-vue-next#2660)

    Co-Authored-By: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

commit 6733770
Author: Jukka Raimovaara <roska@mentalhouse.fi>
Date:   Wed Apr 30 05:15:02 2025 +0300

    chore: update depencies

commit 2b37c18
Author: Jukka Raimovaara <roska@mentalhouse.fi>
Date:   Wed Apr 30 04:36:46 2025 +0300

    fix(BTabs): corrent classes on ssr (bootstrap-vue-next#2664)

    fix(BTabs): corrent classes on ssr
    fix(BTabs): fix another recursion error

commit 99718eb
Author: Jukka Raimovaara <roska@mentalhouse.fi>
Date:   Wed Apr 30 04:20:00 2025 +0300

    Changes to public composables (bootstrap-vue-next#2425)

    feat(BAlert)!: make act like toast, useShowHide.
    feat(useShowHide): create triggerRegistry for adding external triggers (like in vBToggle)
    fix: type popoverController
    fix(useShowHide): focustrap off at the begining of leave, pass down the trigger to other hide emits.
    fix(vBToggle): keep track of targets
    fix(BPopover)!: change prop content to body to align with other components
    fix(BTooltip)!: change prop content to body to align with other components
    feat(usePopoverController): allow more options
    fix(vBToggle): find late components, ie. inside ClientOnly
    fix(useModalController)!: move props to main level, add slots
    feat(usePopoverController): add slots
    feat(useToastController)!: remove props obj, the parameters are flat now. Add slots, rename pos -> position
    feat(useShowHide): show returns a promise, resolve on show or hide.
    feat(useToggle): toggle any show/hide component
    feat!: controller composables functions return promise, with chainable functions
    feat(useModalController): add support for using syntax in ts
    feat(BModal): add okClass and cancelClass to add classes to the buttons.
    feat(useModalController)!: change of api, check the docs
    fix: inline functional style to show toast,modal and dropdown
    feat(useToggle): add trigger to promise resolve on hide.
    fix(BCarousel): fix v-for updates

commit 340edfd
Author: David W. Gray <dwgray67@hotmail.com>
Date:   Mon Apr 28 18:39:44 2025 -0700

    docs(BTable): parity pass (bootstrap-vue-next#2669)

commit 4dd6c89
Author: Jukka Raimovaara <roska@mentalhouse.fi>
Date:   Mon Apr 28 22:46:31 2025 +0300

    fix(BDropdown): don't calulcate the position when dropdown is not shown.
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.

BTabs only becomes visible on mounted, resulting in CLS
2 participants
0