8000 draft of BApp by xvaara · Pull Request #2732 · bootstrap-vue-next/bootstrap-vue-next · GitHub
[go: up one dir, main page]

Skip to content

draft of BApp #2732

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

draft of BApp #2732

wants to merge 2 commits into from

Conversation

xvaara
Copy link
Contributor
@xvaara xvaara commented Jun 6, 2025

BApp Component

The BApp component is the new recommended way to configure bootstrap-vue-next. It replaces the plugin-based approach and provides better defaults management and orchestrator integration.

Features

  • Defaults Management: Inject and merge component defaults throughout your application
  • Orchestrator Integration: Automatically includes Modal, Toast, and Popover orchestrators
  • Plugin Compatibility: Works alongside existing plugins for backward compatibility
  • Type Safety: Full TypeScript support with proper type inference
  • RTL Support: Built-in right-to-left language support
  • Flexible Teleporting: Control where orchestrators are rendered in the DOM

Basic Usage

<template>
  <BApp>
    <!-- Your application content -->
    <router-view />
  </BApp>
</template>

<script setup lang="ts">
import {BApp} from 'bootstrap-vue-next'
</script>

Configuration

Setting Component Defaults

<template>
  <BApp :defaults="appDefaults">
    <!-- Your application content -->
  </BApp>
</template>

<script setup lang="ts">
import {BApp} from 'bootstrap-vue-next'

const appDefaults = {
  BButton: {
    variant: 'primary',
    size: 'sm',
  },
  BModal: {
    centered: true,
    noCloseOnBackdrop: true,
  },
  BToast: {
    variant: 'success',
    solid: true,
  },
}
</script>

Advanced Defaults Configuration

<template>
  <BApp :defaults="appDefaults" :merge-defaults="true" :deep-merge="true">
    <!-- Your application content -->
  </BApp>
</template>

<script setup lang="ts">
import {BApp} from 'bootstrap-vue-next'

const appDefaults = {
  BButton: {
    variant: 'primary',
    size: 'sm',
  },
}
</script>

Orchestrator Configuration

<template>
  <BApp :teleport-to="'body'" :append-toast="true">
    <!-- Your application content -->
  </BApp>
</template>

Disabling Orchestrators

<template>
  <BApp :no-modals="true" :no-toasts="true" :no-popovers="true">
    <!-- Your application content -->
  </BApp>
</template>

RTL Configuration

<template>
  <BApp :rtl="rtlConfig">
    <!-- Your application content -->
  </BApp>
</template>

<script setup lang="ts">
import {BApp} from 'bootstrap-vue-next'

const rtlConfig = {
  rtlInitial: true,
  localeInitial: 'ar',
}
</script>

Migration from Plugins

Before (Plugin-based)

import {createApp} from 'vue'
import {createBootstrap} from 'bootstrap-vue-next'

const app = createApp(App)

app.use(
  createBootstrap({
    components: {
      BButton: {
        variant: 'primary',
      },
    },
  })
)

After (BApp-based)

<template>
  <BApp :defaults="{BButton: {variant: 'primary'}}">
    <App />
  </BApp>
</template>

<script setup lang="ts">
import {BApp} from 'bootstrap-vue-next'
import App from './App.vue'
</script>

Props

Prop Type Default Description
defaults Partial<BvnComponentProps> undefined Component defaults to apply globally
mergeDefaults boolean false Whether to merge with existing defaults
deepMerge boolean false Whether to perform deep merge of nested objects
teleportTo TeleportProps['to'] undefined Where to teleport the orchestrator container
noModals boolean false Whether to disable modal orchestrator
noToasts boolean false Whether to disable toast orchestrator
noPopovers boolean false Whether to disable popover orchestrator
noOrchestrator boolean false Whether to disable all orchestrators
appendToast boolean false Whether new toasts should be appended to the list
inhert boolean false Whether to inherit parent orchestrator controllers
rtl boolean | RTLConfig false RTL configuration object or boolean

RTL Configuration Object

interface RTLConfig {
  rtlInitial: boolean // Initial RTL state
  localeInitial?: string // Initial locale
}

Composables

When using BApp, the following composables work without requiring plugin installation:

  • useToastController() - Create and manage toasts programmatically
  • useModalController() - Create and manage modals programmatically
  • usePopoverController() - Create and manage popovers programmatically

Internal Features

The BApp component automatically provides several internal services:

  • Show/Hide Registry: Global registry for show/hide components
  • Modal Manager: Stack management for multiple modals
  • Breadcrumb Service: Global breadcrumb item management
  • RTL Service: Right-to-left text direction support

Default Merging Behavior

The component supports three modes for handling defaults:

  1. Replace Mode (default): defaults prop completely replaces any existing defaults
  2. Merge Mode (mergeDefaults: true): Shallow merge with existing defaults
  3. Deep Merge Mode (mergeDefaults: true, deepMerge: true): Deep merge nested objects

Teleporting

By default, orchestrators render inline. Use teleportTo to render them elsewhere:

<template>
  <BApp teleport-to="body">
    <!-- Orchestrators will render in document.body -->
  </BApp>
</template>

Backward Compatibility

The BApp component is fully backward compatible with existing plugin-based setups. You can gradually migrate by:

  1. Adding BApp to your root component
  2. Moving defaults from plugin configuration to BApp props
  3. Removing plugin installations once migration is complete

The plugins will show deprecation warnings but continue to work until removed in a future version.

Notes

  • Only one BApp or orchestrator should be active at a time per application
  • The component uses Vue's provide/inject system for dependency injection
  • All orchestrators are automatically teleported when teleportTo is specified
  • The component inherits all attributes and passes them to the default slot

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

Copy link

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

Copy link
coderabbitai bot commented Jun 6, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

@dwgray
Copy link
Member
dwgray commented Jun 6, 2025

@xvaara, I really like this for the core setup. It's what I would use in my app, given a choice between this and the current plugin.

The main question I have is about tree shaking. As @VividLemon mentioned previously, there is some segment of our user base that is quite concerned about the deployed size of BSVN. If we eventually deprecate the plugins and only allow this method of installation, do we effectively disable tree shaking?

@VividLemon
Copy link
Member

@xvaara, I really like this for the core setup. It's what I would use in my app, given a choice between this and the current plugin.

The main question I have is about tree shaking. As @VividLemon mentioned previously, there is some segment of our user base that is quite concerned about the deployed size of BSVN. If we eventually deprecate the plugins and only allow this method of installation, do we effectively disable tree shaking?

I think the best solution to this is to effectively give people the tools to build their own "bapp" and document how to do it well

teleportTo: undefined,
defaults: undefined,
mergeDefaults: false,
deepMerge: false,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe mergeDefaults is boolean | function to where the function is the algorithm to use for merging?

Copy link
Member

Choose a reason for hiding this comment

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

I generally dislike props that just effect the behavior of other props. Begs the question why it's not just an object

@xvaara
Copy link
Contributor Author
xvaara commented Jun 10, 2025

The main question I have is about tree shaking. As @VividLemon mentioned previously, there is some segment of our user base that is quite concerned about the deployed size of BSVN. If we eventually deprecate the plugins and only allow this method of installation, do we effectively disable tree shaking?

@dwgray BApp or the orchestrators imports nothing complex, just keys and conditionalTeleport, so if the user doesn't import them or the composables there shouldn't be any extra components included.

@dwgray
Copy link
Member
dwgray commented Jun 16, 2025

The main question I have is about tree shaking. As @VividLemon mentioned previously, there is some segment of our user base that is quite concerned about the deployed size of BSVN. If we eventually deprecate the plugins and only allow this method of installation, do we effectively disable tree shaking?

@dwgray BApp or the orchestrators imports nothing complex, just keys and conditionalTeleport, so if the user doesn't import them or the composables there shouldn't be any extra components included.

@xvaara I've been thinking about this some more. If this doesn't significantly affect tree shaking, I am still a bit torn.

I'd very much prefer it if we land on one solution or the other, rather than maintaining both. @VividLemon 's suggestion of "give people the tools to build their own 'bapp' and document how to do it well" sounds appealing as a solution to only maintaining one implementation, but that really ends up being what I consider a scaffolding solution in one way or the other and moves the burden of managing changes over time on the user of the library (I wrote a Medium article on this a while back - just to show how frustrating I find it).

Advantages of BApp:

  • Easier initial use
  • More flexibility for us to modify how things work without forcing users to migrate/react to breaking changes (see above)
  • This looks like what Vuetify.js does, and I've found their decisions have generally been solid when I've dug into them

Advantages of Plugin:

  • Less churn for existing users
  • More granular control/Less abstraction
  • Feels less notional - enforcing the use of a top-level app moves 8000 us from a set of components that one can use to build a vue.js app, to a framework where we provide the top-level app and the developer fills in their details - this may just be a historical quirk from someone who's dealt with way too many variations on this issue over the years but I lean towards being less notional where we can.

Overall, that does land me on seeing if we can make BApp work, again assuming it doesn't affect tree shaking. I started digging into the mechanics of tree-shaking to convince myself that we would be safe, and quickly realized that this is one of those problems where I wouldn't be able to truly convince myself of the results without experimental evidence. I think it's probably good for us to be able to regression test tree shaking overall, since some part of our user base really cares about this (and others may care more if they dug into it).

My basic idea around this is to have a small project that we can build and establish baseline sizes to confirm that we've not changed the pay-to-play nature of the tree shaking. We should then be able to just change the target bsvn installation in the package.json file and rebuild to see how sizes are affected.

Here's the stats for a recent build without the BApp changes:

Simple Vue.js/Vite app using create vue@latest

vite v6.2.4 building for production...
✓ 26 modules transformed.
dist/index.html                  0.43 kB │ gzip:  0.28 kB
dist/assets/index-TXLObeWa.css   3.71 kB │ gzip:  1.19 kB
dist/assets/index-usgfJ6g8.js   69.64 kB │ gzip: 27.43 kB
✓ built in 865ms

Add bootstrap and BSVN

✓ 136 modules transformed.
dist/index.html                   0.43 kB │ gzip:  0.29 kB
dist/assets/index-BtuzhIq3.css  254.56 kB │ gzip: 34.92 kB
dist/assets/index-91SiXKPq.js    85.35 kB │ gzip: 31.81 kB
✓ built in 1.82s

Add a reference to BLink

vite v6.2.4 building for production...
✓ 136 modules transformed.
dist/index.html                   0.43 kB │ gzip:  0.29 kB
dist/assets/index-BRDhJoMO.css  254.56 kB │ gzip: 34.92 kB
dist/assets/index-CMzBWzqN.js    92.56 kB │ gzip: 34.24 kB
✓ built in 1.50s

Add a reference to BAvatar

vite v6.2.4 building for production...
✓ 136 modules transformed.
dist/index.html                   0.43 kB │ gzip:  0.28 kB
dist/assets/index-vRN9tOtg.css  254.56 kB │ gzip: 34.92 kB
dist/assets/index-r0dbNEhh.js   101.61 kB │ gzip: 36.74 kB
✓ built in 1.58s

Overall, these seem like reasonable results and show that adding references to new components increases the size of the packet (presumably more than the reference). I also did a bit of digging into the generated files to prove to myself that there weren't references to BLink or BAvatar in the generated results until I added them in my app.

The place where I stalled out is that I wasn't able to change the reference to BSVN to @xvaara's BApp branch. I think that's because it doesn't build? But it may be because I don't have the syntax right. Here's what I tried:

    "bootstrap-vue-next": "bootstrap-vue-next/bootstrap-vue-next#bapp-composables-makeover",

I've pushed the project up to https://github.com/[dwgray/bsvn-tree-shake](https://github.com/dwgray/bsvn-tree-shake) - let me know if you think this is a reasonable way to approach confirming our tree-shaking (and that we don't degrade it with features like this) @xvaara and @VividLemon and if I should add other features to test (I'm thinking BModal or something that requires an orchestrator would be a good next step).

P.S. Looks like I accidentally wrote over your comment rather than replying to it - I think I managed to restore the original comment, but that's why it's tagged as edited by me...

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.

3 participants
0