(null);
const [width, setWidth] = useState(0);
const measure = async () => {
if (!box.current) return;
const rect = await host.measure(box.current);
setWidth(rect.width);
};
return (
void measure()}>
{width > 0 ? `${width}px wide` : 'Click to measure'}
);
}
export default defineIsolate(Measured);
```
A library that measures on every render (tooltips that position themselves, virtualised lists, auto-sizing text) needs rewriting around these calls, or it belongs on the page rather than in an isolate.
## Globals that libraries reach for
In an isolate with a surface, `document` is the render bridge's DOM subset and `window` is the worker's own global. A headless isolate has neither. That breaks some libraries in ways that are easy to miss:
- **`document.body`** is a detached element. A widget that appends a portal, a tooltip or a modal to it renders nothing on screen. Render it inside your own root instead.
- **`localStorage` and `sessionStorage`** don't exist in workers. `IndexedDB` does. To keep state across a restart, publish it to a topic ([persistent topics](https://isoloop.dev/docs/hosting.md#persistent-topics-and-a-discarded-tab) survive a reload).
- **The page's `window`** isn't there: no `innerWidth`, `matchMedia` or `history`, and `location` is the worker script's URL. Navigation goes through `host.navigate`, with the `navigate` grant ([contracts and grants](https://isoloop.dev/docs/contracts.md)).
- **Tags the page won't create.** The page builds only allow-listed HTML and SVG tags: an unknown tag becomes a `div` (`g` inside SVG), and `script`, `iframe`, `style` and `on*` attributes are never created. URLs are limited to `http(s):`, `mailto:` and relative ones. A widget that injects a `