# Lifecycle

- Human documentation: [https://docs.univer.ai/guides/bases/getting-started/lifecycle](https://docs.univer.ai/guides/bases/getting-started/lifecycle)

- Agent Markdown: [https://docs.univer.ai/guides/bases/getting-started/lifecycle.md](https://docs.univer.ai/guides/bases/getting-started/lifecycle.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.4`

- Source: [bases/getting-started/lifecycle.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/bases/getting-started/lifecycle.mdx)

---

## Global lifecycle

* **Starting**: Initialization, before any business unit exists.
* **Ready**: The first business unit has been created; later units do not retrigger it.
* **Rendered**: The standard UI has performed its first render switch, not necessarily finished all asynchronous content.
* **Steady**: The standard UI enters this stage after a delay following Rendered, without waiting for all asynchronous tasks.

### Facade API

```typescript
const currentStage = univerAPI.getCurrentLifecycleStage()

const disposable = univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => {
  console.log(stage)
})
```

> [!WARNING: What the event reports]
> `LifeCycleChanged` reports Univer’s global stage. For example, loading plugin B after global `Ready` calls B’s `onReady()`, but does not emit another global `Ready` event.
> 
> When you add a listener, its callback may immediately receive the current stage, including `Starting`. To simply check the current stage, call `univerAPI.getCurrentLifecycleStage()` directly.

To remove a listener, you can use the returned `disposable` object:

```typescript
disposable.dispose()
```

## Plugin lifecycle hooks

A plugin runs `onStarting()` when it loads, then catches up to the current global stage. Choose when B loads to compare its hook calls with A’s.

Plugin hooks run in order: `onStarting()` → `onReady()` → `onRendered()` → `onSteady()`. A late plugin catches up synchronously to the current global stage without changing that stage.

General plugins load on registration; business-type plugins usually load before the first unit of that type is constructed. New plugins for an already started type load in a deferred batch. Explicit dependencies can trigger earlier loading.

Each batch invokes hooks synchronously, stage by stage and in dependency order, without awaiting asynchronous work. Check the specific unit, DOM element, or resource before accessing it.
