跪拜 Guibai
← Back to the summary

A Forced Component Library Upgrade Broke Layouts, Crashed Pages, and Triggered a Three-Day Scolding Spree

Last month, in response to the call for "cost reduction and efficiency" and "unified design standards," our infrastructure team officially pushed the internal Vue component library we had maintained for over two years to the internal NPM registry, forcing all mid- and back-office projects to upgrade to the latest version (v3.0).

On the day of release, we sent a big red envelope in the group chat, celebrating that "the company's frontend infrastructure has reached a new level."

The next day, my WeChat Work was bombarded by leaders from various business lines.

"You changed the default height of the Select component from 32px to 36px, and the layouts of our dozen-plus pages are all misaligned!"

"Why did the new Table component make row-key required? It's throwing errors directly and causing white screens!"

"The DatePicker used to have fallback handling no matter what format you passed in. Now it throws an exception if the format is wrong, and we're getting alerts in production!"

Looking at the 99+ messages of complaint in the group, I smiled bitterly and opened the component library source code. Inside lay more than 80 components and over 3,000 lines of compatibility logic that no one dared to touch.

We intended to build a Swiss Army knife, but in the end, we turned it into a ticking time bomb tied to every business line.

I. The Three "Original Sins" of the Component Library

Many teams, when building their own wheels, think they are doing "technical accumulation." But after going through a few full upgrades, you realize that the pain points of an internal component library are not technical at all—they lie in business coupling.

Sin 1: Writing "Business Components" as "Base Components"

Open our Table component source code, and the template looks roughly like this:

<template>
  <div class="table-wrapper">
    <!-- If export is enabled, show the export button -->
    <ExportBtn v-if="showExport" :params="exportParams" />
    <!-- If permission is set, show batch delete -->
    <BatchDelete v-if="hasAuth('delete')" @success="refresh" />
    <!-- The actual table -->
    <el-table ... />
  </div>
</template>

Looks convenient? That is the beginning of the disaster.

Business requirements are all over the place, so we stuffed "pagination, export, multi-select, filtering, column configuration" all into this one component. As a result, the component's Props reached more than 40. To accommodate different business scenarios, it was filled with code like this:

// Compatibility for business A's export format
const finalExportParams = props.bizType === 'A' ? processA(props) : props;
// Compatibility for business B's specific permissions
const canDelete = props.bizType === 'B' ? true : props.hasAuth;

For the sake of reuse, we turned the entire company's business logic into if-else statements inside the component library. Every time a new business came on board, the component library gained a few more parameters; every time we changed code, we had to run full regression tests.

Sin 2: Siloed "Breaking Changes"

Why did v3.0 cause such public outrage?

Because we thought the previous API design was a mess, and we casually performed a "breaking change":

  1. Changed value to modelValue (to support Vue 3's two-way binding).
  2. Split the previously merged options into data and dict.
  3. Unified adding box-sizing: border-box to all components.

From the infrastructure team's perspective, the new version was extremely elegant and clean. But from the business lines' perspective, adapting to this new version meant modifying hundreds of files and testing the UI for two weeks.

"You only care about whether the design feels nice, not about when we can go live." That was the business line leader's exact words.

Sin 3: Version Misalignment, a Dubbo-Style Dependency Hell

Some old systems are still using v2.2, while new systems use v3.0.

As a result, once we published a common hooks package dependency, the old component library accidentally introduced v3.0's CSS files under certain conditions. The two sets of styles (one 32px, one 36px) fought each other on the same page, making the whole page look like IE6 from ten years ago.

II. How Did I Remedy It Later?

After being scolded for three days, we held an emergency meeting. The final conclusion was: Stop pursuing "perfect reuse". Teach everyone to assemble parts, rather than forcing a whole Transformer on them.

I did three things:

1. Return to "Headless UI"

I directly split that 3,000-line Table component into:

We only provide the most basic atomic capabilities (buttons, input fields, modals), and return the right to assemble these atoms into wheels to the business lines.

2. Remove All "Clever" Default Values

Previously, for "out-of-the-box" convenience, we set the DatePicker default format to YYYY-MM-DD. Now, the default must be empty, forcing the business side to explicitly pass it in.

Components cannot make decisions on behalf of the business. What you think is "user-friendly", the business thinks is "overstepping".

3. Establish an "Escape Hatch" for Breaking Changes

In the future, major component version updates will no longer force full upgrades. We built a legacyAdapter compatibility layer. If the caller uses the v2 pattern, the underlying layer automatically translates it to v3 logic.

You don't have to change your code. We just show a warning, and you can migrate gradually within six months.

III. A Piece of Advice for Peers Who Want to Build a Component Library

If you plan to build an internal component library tomorrow, take my advice:

A component library is not a stage for showing off skills; it is an amplifier of engineering capability. If the foundation is unstable, all you amplify is multiplied pain.

Comments

Top 2 from juejin.cn, machine-translated. The original thread is authoritative.

云沙 1 likes

With all due respect, your infrastructure team simply doesn't have the ability to write a good shared component. The Table component mixes in a large amount of business-coupled logic, and even after the rewrite, they want to stuff input boxes and modals into Table. What do Table and these things have to do with each other? This seriously violates the Single Responsibility Principle. What project teams need are individual building blocks, not a toy assembled from building blocks.

承上启下

666, which company? Very good at passing the buck.