How Taro Next Transforms Cross‑Platform Development: Architecture, Features, and Best Practices

This presentation details the motivations behind rebuilding Taro, introduces the Taro Next architecture and its new capabilities, walks through practical development steps, explains underlying rendering principles for both mini‑program and H5 targets, and outlines performance optimizations and future directions.

Aotu Lab
Aotu Lab
Aotu Lab
How Taro Next Transforms Cross‑Platform Development: Architecture, Features, and Best Practices

Background and Motivation

Taro is an open‑source multi‑end framework that compiles a single React (or Vue) codebase to run on mini‑programs, H5, and React‑Native. After two years of development and more than 25 000 GitHub stars, the original architecture showed several limitations:

Incomplete JSX support because the compiler relied on fragile syntax adaptations.

No source‑map generation, which made debugging difficult.

Complex, fragmented compilation code that was hard to maintain.

Separate runtime implementations for each mini‑program platform, causing duplicated bug‑fixes and feature work.

Only React was officially supported, while many internal teams needed Vue, jQuery, Angular, etc.

Architecture of Taro Next

Taro Next introduces a unified architecture that treats a single platform (e.g., WeChat mini‑program) as the baseline. Framework‑specific component libraries, lifecycle hooks, and APIs are mapped onto this baseline, and missing pieces are supplied at runtime. The runtime is bundled once with Webpack and shared across all target platforms.

Key design points:

Plugin system : internal Taro and Webpack configurations are exposed, allowing developers to install only the plugins they need.

Framework‑agnostic core : React, Vue, and other frameworks can plug into the same DOM/BOM layer.

Lean runtime : duplicated code is eliminated, reducing bundle size and maintenance overhead.

Key Advantages

Powerful : Supports any language or syntax, can render raw HTML, and provides cross‑framework component capabilities.

Fast : Removes heavy AST transformations, accelerates build time, and offers configurable performance options.

Flexible : Developers can customize Taro and Webpack settings via plugins and can install only the dependencies required for their project.

Development Workflow

Preparation

Install the Taro CLI globally. Create a new project with taro init <project-name> or migrate an existing mini‑program with taro convert <source-dir>.

Configure project files ( config/index.js, config/dev.js, config/prod.js) for global, mini‑program, and H5 targets.

Use Babel 7 by adding a babel.config.js file that includes @tarojs/babel-preset and, if needed, framework‑specific presets such as @babel/preset-react or @babel/preset-typescript. The file is loaded with @babel/register, so ESNext syntax can be used in app.config.js and page config files.

Coding

Entry component ( src/app.js) is a normal React Component or Vue instance that imports the chosen framework, global styles, and exposes Taro lifecycle methods (e.g., onLaunch, onShow).

Page components follow the same pattern. In React they import UI primitives from @tarojs/components; in Vue they are processed by vue-loader.

Componentization : All framework components are supported. During compilation component styles are merged into the page’s style sheet because mini‑programs do not support true component‑level style isolation.

Lifecycle handling : Taro splits lifecycle into the original framework hooks (e.g., componentDidMount) and mini‑program‑specific extensions (e.g., onReady).

Component library mapping : Mini‑program components are mapped to Web Components for H5, enabling a single component source to work on both environments.

API wrapper : Import import Taro from '@tarojs/taro'. On mini‑programs the wrapper forwards calls to the native API and adds Promise‑based handling; on H5 a lightweight mock implements the most common APIs.

Refs : ref returns a Taro HTMLElement object, allowing direct DOM manipulation. To obtain true node information (size, position) the mini‑program createSelectorQuery API must be used.

Advanced Topics

State management : React‑Redux, MobX, Vuex, etc., can be used directly without additional adapters.

Styling : Enable CSS Modules in config to get scoped styles. For CSS‑in‑JS, Linaria is supported; configure it via Babel plugins.

HTML rendering : Taro Next ships a lightweight HTMLParser that parses an HTML string into a data structure compatible with setData, avoiding large third‑party parsers and an extra DOM traversal step.

Multi‑End Development

Native mini‑program pages/components are added through the usingComponents field in the page’s JSON config.

Conditional code can use the global TARO_ENV variable (values: weapp, h5, rn, etc.). Excessive branching is discouraged.

Platform‑specific files follow the naming convention filename.<platform>.js. Webpack resolves the correct file based on the target platform.

Cross‑framework components can be written with a jQuery‑like API, making them usable in both React and Vue projects.

Performance Optimizations

SetData minimization : During the hydrate phase Taro Next analyses the rendered tree and extracts only the data actually accessed by the view, resulting in the smallest possible setData payload.

Path‑based updates : The diff of the old and new Taro DOM trees is translated into mini‑program path updates, further reducing the amount of data sent to the view layer.

Prerender : A placeholder page can be generated at build time; the real DOM is rendered only after the heavy setData operation finishes, eliminating the white‑screen effect.

React optimizations : shouldComponentUpdate, PureComponent, and React.memo are fully supported.

VirtualList : A built‑in virtual list component renders only items visible in the viewport, dramatically improving long‑list performance.

Bundle size reduction : Webpack tree‑shaking, side‑effects elimination, and the webpack-bundle-analyzer plugin help identify and drop unused code.

Code splitting : The splitChunks configuration can separate node_modules used by sub‑packages into their own chunks, keeping the main bundle lean.

Implementation Details

Design Philosophy

Both React and Vue are run on mini‑programs by providing a thin DOM and BOM layer that mimics browser APIs. This allows existing framework code to execute unchanged while the runtime translates DOM operations into mini‑program setData calls.

DOM Rendering Strategy

Static WXML templates are generated for each component type. At runtime a Taro DOM tree is built, then the templates are recursively combined based on the tree structure. Because mini‑programs cannot create nodes dynamically, the renderer uses template inclusion and attribute enumeration to produce a fully static WXML that reflects the dynamic tree.

React Integration

The taro-react package implements a custom React renderer (host config) that outputs a Taro DOM tree. taro-runtime provides createReactPage which receives the tree, runs the hydrate step, and finally calls setData on the mini‑program page.

Vue Integration

Vue integration is simpler because Vue’s virtual DOM already matches the needed shape. taro-runtime exposes createVuePage which builds the Taro DOM tree from Vue’s render output, performs hydration, and triggers setData.

Mini‑Program and H5 Build Pipelines

For both targets the user’s React/Vue source is processed by Webpack with the appropriate loader ( @tarojs/webpack5-runner for mini‑programs, standard Webpack for H5). After bundling, framework‑specific adapters inject the shared DOM/BOM layer, and the final bundle is executed on the target platform.

Summary

Taro Next resolves the architectural shortcomings of the original Taro by unifying the runtime, adding full JSX support, generating source maps, and opening the framework to Vue, jQuery, Angular, and other ecosystems. Its plugin‑based configuration, optimized build pipeline, and runtime‑level rendering enable fast, flexible, and maintainable cross‑platform development.

frontendPerformanceCross-PlatformFrameworkTaro
Aotu Lab
Written by

Aotu Lab

Aotu Lab, founded in October 2015, is a front-end engineering team serving multi-platform products. The articles in this public account are intended to share and discuss technology, reflecting only the personal views of Aotu Lab members and not the official stance of JD.com Technology.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.