Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/content/api/hot-module-replacement.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (module.hot) {

The following methods are supported...

## Module API

### `accept`

Expand All @@ -35,6 +36,23 @@ module.hot.accept(
)
```

When using ESM `import` all imported symbols from `dependencies` are automatically updated. Note: The dependency string must match exactly with the `from` string in the `import`. In some cases `callback` can even be omitted. Using `require()` in the `callback` doesn't make sense here.

When using CommonJS you need to update dependencies manually by using `require()` in the `callback`. Omitting the `callback` doesn't make sense here.

### `accept` (self)

Accept updates for itself.

``` js
module.hot.accept(
errorHandler // Function to handle errors when evaluating the new version
)
```

When this module or dependencies are updated, this module can be disposed and re-evaluated without informing parents. This makes sense if this module has no exports (or exports are updated in another way).

The `errorHandler` is fired when the evaluation of this module (or dependencies) has thrown an exception.

### `decline`

Expand All @@ -46,6 +64,17 @@ module.hot.decline(
)
```

Flag a dependency as not-update-able. This makes sense when changing exports of this dependency can be handled or handling is not implemented yet. Depending on your HMR management code an update to this dependencies (or unaccepted dependencies of it) usually causes a full-reload of the page.

### `decline` (self)

Reject updates for itself.

``` js
module.hot.decline()
```

Flag this module as not-update-able. This make sense when this module has inrevertable side-effects, or HMR handling is not implemented for this module yet. Depending on your HMR management code an update to this module (or unaccepted dependencies) usually causes a full-reload of the page.

### `dispose` (or `addDisposeHandler`)

Expand All @@ -66,6 +95,7 @@ Remove the callback added via `dispose` or `addDisposeHandler`.
module.hot.removeDisposeHandler(callback)
```

## Management API

### `status`

Expand Down