@servicetitan/docs-uikit 40.3.0 → 40.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -48,6 +48,8 @@ const Root = () => {
|
|
|
48
48
|
`hashRouting` requires `trackViewsManually: true` in the [`application`](./init.mdx#applicationconfig) config. Otherwise the SDK also starts a view for each URL change, and RUM records each route twice.
|
|
49
49
|
:::
|
|
50
50
|
|
|
51
|
+
With `react-router-dom` v5, `hashRouting` starts each view as soon as the router navigates, before the page renders, so the page's first requests count toward its view. With v6 and later, it starts each view after the page renders, but before the page's `componentDidMount` and effects send requests.
|
|
52
|
+
|
|
51
53
|
## Parameters
|
|
52
54
|
|
|
53
55
|
| Name | Type | Description |
|
|
@@ -6,22 +6,22 @@ A host is an application, or MFE, that uses [`Loader`](../web-components/loader)
|
|
|
6
6
|
|
|
7
7
|
## Configuration
|
|
8
8
|
|
|
9
|
-
Set `cli.
|
|
9
|
+
Set `cli.provide-shared-dependencies` to `true` in the application's `package.json`.
|
|
10
10
|
|
|
11
11
|
:::caution
|
|
12
|
-
`
|
|
12
|
+
`provide-shared-dependencies` only applies to applications. MFEs that load other MFEs do not need this setting or any additional configuration. Setting it on a package marked `cli.web-component` fails the build.
|
|
13
13
|
:::
|
|
14
14
|
|
|
15
15
|
```json title="package.json"
|
|
16
16
|
{
|
|
17
17
|
"cli": {
|
|
18
|
-
"
|
|
18
|
+
"provide-shared-dependencies": true
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
:::note
|
|
24
|
-
In versions before **
|
|
24
|
+
In versions before **40.4.0**, this setting was named `cli.expose-shared-dependencies`, and in versions before **36.4.0** it was under `cli.webpack.expose-shared-dependencies`. The old names still work for backward compatibility, but `startup` logs a deprecation warning. They will be removed in a future major release.
|
|
25
25
|
:::
|
|
26
26
|
|
|
27
27
|
### Design system
|
|
@@ -30,7 +30,7 @@ MFE's are not required to use all the default dependencies; `startup` and `Loade
|
|
|
30
30
|
To customize which dependencies are shared, set `cli.shared-dependencies` to an object that maps dependencies to `SharedDependencies.{name}`. By convention `{name}` is the camel-cased package name.
|
|
31
31
|
|
|
32
32
|
:::note
|
|
33
|
-
In versions before **36.4.0**, this setting was under `cli.webpack.shared-dependencies`. The old location still works for backward compatibility.
|
|
33
|
+
In versions before **36.4.0**, this setting was under `cli.webpack.shared-dependencies`. The old location still works for backward compatibility, but `startup` logs a deprecation warning. It will be removed in a future major release.
|
|
34
34
|
:::
|
|
35
35
|
|
|
36
36
|
- Use the special **defaults** key with the empty string to incorporate the default list.
|
package/docs/react-ioc.mdx
CHANGED
|
@@ -104,6 +104,69 @@ import { Provider } from '@servicetitan/react-ioc';
|
|
|
104
104
|
| `errorFallback` | `ReactNode` | (optional) Rendered when initialization throws or [duplicate tokens](#runtime-checks) are found. Defaults to `<h2>Error</h2>`. |
|
|
105
105
|
| `children` | `ReactNode` | The sub-tree that can consume the bindings. |
|
|
106
106
|
|
|
107
|
+
#### Bindings are read once at mount {#bindings-read-once}
|
|
108
|
+
|
|
109
|
+
`Provider` reads `singletons` and `instances` once, when it mounts, and binds them to its container. Changes to these props on later renders are ignored. That includes changing a [`useValue`](#entry-shapes): the provided value does not change, and consumers keep getting the value from the first render.
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import { Provider, symbolToken } from '@servicetitan/react-ioc';
|
|
113
|
+
|
|
114
|
+
const CONFIG_TOKEN = symbolToken<AppConfig>('APP_CONFIG');
|
|
115
|
+
|
|
116
|
+
// ❌ Consumers keep getting the first `config`, even when the prop changes.
|
|
117
|
+
const App = ({ config }: { config: AppConfig }) => (
|
|
118
|
+
<Provider singletons={[{ provide: CONFIG_TOKEN, useValue: config }]}>
|
|
119
|
+
<Page />
|
|
120
|
+
</Provider>
|
|
121
|
+
);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
To pass values that change over time, provide a store and update its observable state instead of replacing the bound value. For example, with a MobX store:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import { Provider, useDependencies } from '@servicetitan/react-ioc';
|
|
128
|
+
import { action, makeObservable, observable } from 'mobx';
|
|
129
|
+
import { observer } from 'mobx-react';
|
|
130
|
+
import { useEffect, useState } from 'react';
|
|
131
|
+
|
|
132
|
+
class ConfigStore {
|
|
133
|
+
@observable.ref config: AppConfig;
|
|
134
|
+
|
|
135
|
+
constructor(config: AppConfig) {
|
|
136
|
+
this.config = config;
|
|
137
|
+
makeObservable(this);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@action
|
|
141
|
+
setConfig = (config: AppConfig) => {
|
|
142
|
+
this.config = config;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ✅ The bound store never changes; only its `config` does.
|
|
147
|
+
const App = ({ config }: { config: AppConfig }) => {
|
|
148
|
+
const [configStore] = useState(() => new ConfigStore(config));
|
|
149
|
+
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
configStore.setConfig(config);
|
|
152
|
+
}, [configStore, config]);
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<Provider singletons={[{ provide: ConfigStore, useValue: configStore }]}>
|
|
156
|
+
<Page />
|
|
157
|
+
</Provider>
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// `observer` re-renders the component when `config` changes.
|
|
162
|
+
const Page = observer(() => {
|
|
163
|
+
const [configStore] = useDependencies(ConfigStore);
|
|
164
|
+
return <div>{configStore.config.apiUrl}</div>;
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Alternatively, give the `Provider` a new `key` to remount it with the new value. This rebuilds every binding and remounts everything below the `Provider`, so prefer the store approach.
|
|
169
|
+
|
|
107
170
|
### `@provide` {#provide}
|
|
108
171
|
|
|
109
172
|
Decorator equivalent of `<Provider>`. Wraps a function or class component.
|
|
@@ -178,12 +241,12 @@ const CONFIG_TOKEN = symbolToken<AppConfig>('APP_CONFIG');
|
|
|
178
241
|
<Provider singletons={[{ provide: Store }]} />;
|
|
179
242
|
```
|
|
180
243
|
|
|
181
|
-
| Field | Type | Description
|
|
182
|
-
| :--------- | :-------------------- |
|
|
183
|
-
| `provide` | [`Token<T>`](#tokens) | The identifier consumers ask for.
|
|
184
|
-
| `useClass` | `Newable<T>` | (optional) Class to instantiate. If omitted on a class token, `provide` is used as both token and implementation.
|
|
185
|
-
| `useValue` | `T` | (optional) Pre-built value. Cannot be combined with `useClass`. Only valid in `singletons`.
|
|
186
|
-
| `inherit` | `true` | (optional) See [Reusing a parent binding](#inherit). Only valid in `singletons`.
|
|
244
|
+
| Field | Type | Description |
|
|
245
|
+
| :--------- | :-------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
246
|
+
| `provide` | [`Token<T>`](#tokens) | The identifier consumers ask for. |
|
|
247
|
+
| `useClass` | `Newable<T>` | (optional) Class to instantiate. If omitted on a class token, `provide` is used as both token and implementation. |
|
|
248
|
+
| `useValue` | `T` | (optional) Pre-built value. Cannot be combined with `useClass`. Only valid in `singletons`. Read once at mount; see [Bindings are read once at mount](#bindings-read-once). |
|
|
249
|
+
| `inherit` | `true` | (optional) See [Reusing a parent binding](#inherit). Only valid in `singletons`. |
|
|
187
250
|
|
|
188
251
|
### Reusing a parent binding {#inherit}
|
|
189
252
|
|
|
@@ -10,7 +10,7 @@ Checks MFE/host dependency compatibility.
|
|
|
10
10
|
Use `mfe-check` to verify that an MFE's shared dependencies are compatible with the host application. This determines whether the MFE can use a "light" or "full" bundle (see [Sharing Dependencies](../microfrontends/sharing-dependencies)).
|
|
11
11
|
|
|
12
12
|
:::caution
|
|
13
|
-
The host must be configured to [
|
|
13
|
+
The host must be configured to [provide shared dependencies](../microfrontends/hosting#configuration) else `mfe-check` exits with an error.
|
|
14
14
|
:::
|
|
15
15
|
|
|
16
16
|
## Options
|
|
@@ -47,7 +47,7 @@ npx startup mfe-check \
|
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
:::caution
|
|
50
|
-
The first `--host-package-json` must be the host package's own `package.json`. This is the file from which the command reads the [`
|
|
50
|
+
The first `--host-package-json` must be the host package's own `package.json`. This is the file from which the command reads the [`provide-shared-dependencies`](../microfrontends/hosting#configuration) (and [`shared-dependencies`](../microfrontends/sharing-dependencies)) configuration. Dependencies are merged from all specified files, with the first file's versions taking precedence.
|
|
51
51
|
:::
|
|
52
52
|
|
|
53
53
|
</TabItem>
|
|
@@ -82,13 +82,13 @@ Result: full bundle required
|
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
</TabItem>
|
|
85
|
-
<TabItem value="shared-dependencies-not-
|
|
85
|
+
<TabItem value="shared-dependencies-not-provided" label="Shared dependencies not provided">
|
|
86
86
|
|
|
87
|
-
When the host does not
|
|
87
|
+
When the host does not provide shared dependencies, it reports the error:
|
|
88
88
|
|
|
89
89
|
```
|
|
90
90
|
Checking @servicetitan/my-mfe...
|
|
91
|
-
|
|
91
|
+
provide-shared-dependencies is not enabled in host package.json
|
|
92
92
|
Result: full bundle required
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -128,7 +128,7 @@ Result: full bundle required
|
|
|
128
128
|
```
|
|
129
129
|
|
|
130
130
|
</TabItem>
|
|
131
|
-
<TabItem value="shared-dependencies-not-
|
|
131
|
+
<TabItem value="shared-dependencies-not-provided" label="Shared dependencies not provided">
|
|
132
132
|
|
|
133
133
|
```json
|
|
134
134
|
{
|