StateDefinitionBoundary
classRetries the mod component when a State it read becomes defined, and shows the failure on screen while it is broken. A mod can declare a new owned State and read it from its view in one edit. The bundle carrying the reader travels a different channel than the extension host's definition commit, and the view's rehydrate can only report what the host holds at that instant — so the reader can render before the definition exists and throw. Without this boundary that throw kills the React root and the view stays dead until the window reloads, which is the whole point of the live loop lost for the edit a mod author is most likely to make. Remounting on the definition signal is targeted rather than merely tolerant: the definition set is the input the failed render was missing, so its arrival is the one event that can make the same render succeed. A failure that the definition signal never resolves is a real bug in the mod, and rendering nothing for it is what makes every mod failure look identical from the outside. The message is painted into the view itself, because the author is looking at the view — not at a diagnostics channel they would have to know exists. Reporting through `onError` continues regardless.
Import
import { StateDefinitionBoundary } from '@modular/sdk/view';Members21
- context
unknownIf using React Context, re-declare this in your class to be the `React.ContextType` of your `static contextType`. Should be used with type annotation or static contextType.
- contextTypeoptional
Context<any> | undefinedIf set, `this.context` will be set at runtime to the current value of the given Context.
- props
Readonly<P>- propTypesoptional
anyIgnored by React.
- state
StateDefinitionBoundaryState- componentDidCatch()
(error: Error, info: ErrorInfo) => voidCatches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.
- componentDidMount()
() => voidCalled immediately after a component is mounted. Setting state here will trigger re-rendering.
- componentDidUpdate()optional
(prevProps: Readonly<P>, prevState: Readonly<S>, snapshot?: SS) => voidCalled immediately after updating occurs. Not called for the initial render. The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
- componentWillMount()optional
() => voidCalled immediately before mounting occurs, and before Component.render. Avoid introducing any side-effects or subscriptions in this method. Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
- componentWillReceiveProps()optional
(nextProps: Readonly<P>, nextContext: any) => voidCalled when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes. Calling Component.setState generally does not trigger this method. Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
- componentWillUnmount()
() => voidCalled immediately before a component is destroyed. Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in `componentDidMount`.
- componentWillUpdate()optional
(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any) => voidCalled immediately before rendering when new props or state is received. Not called for the initial render. Note: You cannot call Component.setState here. Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
- forceUpdate()
(callback?: () => void) => void- getDerivedStateFromError()
(error: unknown) => Partial<StateDefinitionBoundaryState>- getSnapshotBeforeUpdate()optional
(prevProps: Readonly<P>, prevState: Readonly<S>) => SS | nullRuns before React applies the result of render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before render causes changes to it. Note: the presence of this method prevents any of the deprecated lifecycle events from running.
- render()
() => ReactNode- setState()
<K extends keyof S>(state: ((prevState: Readonly<S>, props: Readonly<P>) => Pick<S, K> | S | null) | (Pick<S, K> | S | null), callback?: () => void) => void- shouldComponentUpdate()optional
(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any) => booleanCalled to determine whether the change in props and state should trigger a re-render. `Component` always returns true. `PureComponent` implements a shallow comparison on props and state and returns true if any props or states have changed. If false is returned, Component.render, `componentWillUpdate` and `componentDidUpdate` will not be called.
- UNSAFE_componentWillMount()optional
() => voidCalled immediately before mounting occurs, and before Component.render. Avoid introducing any side-effects or subscriptions in this method. This method will not stop working in React 17. Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
- UNSAFE_componentWillReceiveProps()optional
(nextProps: Readonly<P>, nextContext: any) => voidCalled when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes. Calling Component.setState generally does not trigger this method. This method will not stop working in React 17. Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.
- UNSAFE_componentWillUpdate()optional
(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any) => voidCalled immediately before rendering when new props or state is received. Not called for the initial render. Note: You cannot call Component.setState here. This method will not stop working in React 17. Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.