webf-api-compatibility
Check Web API and CSS feature compatibility in WebF - determine what JavaScript APIs, DOM…
Understand and work with WebF's async rendering model - handle onscreen/offscreen events and element measurements correctly. Use when getBoundingClientRect returns zeros, computed styles are incorrect, measurements fail, or elements don't layout as expected.
$ npx -y skills add openwebf/webf --skill webf-async-rendering --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/webf-async-renderingContext preview
The summary Claude sees to decide when to auto-load this skill.
Understand and work with WebF's async rendering model - handle onscreen/offscreen events and element measurements correctly. Use when getBoundingClientRect returns zeros, computed styles are incorrect, measurements fail, or elements don't layout as expected.
name: webf-async-rendering description: Understand and work with WebF's async rendering model - handle onscreen/offscreen events and element measurements correctly. Use when getBoundingClientRect returns zeros, computed styles are incorrect, measurements fail, or elements don't layout as expected.
> **Note**: WebF development is nearly identical to web development - you use the same tools (Vite, npm, Vitest), same frameworks (React, Vue, Svelte), and same deployment services (Vercel, Netlify). This skill covers **one of the 3 key differences**: WebF's async rendering model. The other two differences are API compatibility and routing.
**This is the #1 most important concept to understand when moving from browser development to WebF.**
When you modify the DOM, the browser **immediately** performs layout calculations:
// Browser behavior
const div = document.createElement('div');
document.body.appendChild(div);
console.log(div.getBoundingClientRect()); // ✅ Returns real dimensionsLayout happens **synchronously** - you get dimensions right away, but this can cause performance issues (layout thrashing).
When you modify the DOM, WebF **batches** the changes and processes them in the next rendering frame:
// WebF behavior
const div = document.createElement('div');
document.body.appendChild(div);
console.log(div.getBoundingClientRect()); // ❌ Returns zeros! Not laid out yet.Layout happens **asynchronously** - elements exist in the DOM tree but haven't been measured/positioned yet.
**Performance**: WebF's async rendering is **20x cheaper** than browser synchronous layout!
**Trade-off**: You must explicitly wait for layout to complete before measuring elements.
WebF provides two non-standard events to handle the async lifecycle:
| Event | When It Fires | Purpose | |-------|---------------|---------| | `onscreen` | Element has been laid out and rendered | Safe to measure dimensions, get computed styles | | `offscreen` | Element removed from render tree | Cleanup and resource management |
**Think of these like `IntersectionObserver` but for layout lifecycle, not viewport visibility.**
// DON'T DO THIS - Will return 0 or incorrect values
const div = document.createElement('div');
div.textContent = 'Hello WebF';
document.body.appendChild(div);
const rect = div.getBoundingClientRect(); // ❌ Returns zeros!
console.log(rect.width); // 0
console.log(rect.height); // 0// DO THIS - Wait for layout to complete
const div = document.createElement('div');
div.textContent = 'Hello WebF';
div.addEventListener('onscreen', () => {
// Element is now laid out - safe to measure!
const rect = div.getBoundingClientRect(); // ✅ Real dimensions
console.log(`Width: ${rect.width}, Height: ${rect.height}`);
});
document.body.appendChild(div);For React developers, WebF provides a convenient hook:
import { useEffect, useRef } from 'react';
function MyComponent() {
const ref = useRef(null);
useEffect(() => {
// ❌ Element not laid out yet!
const rect = ref.current.getBoundingClientRect();
console.log(rect); // Will be zeros
}, []);
return <div ref={ref}>Content</div>;
}import { useFlutterAttached } from '@openwebf/react-core-ui';
function MyComponent() {
const ref = useFlutterAttached(
() => {
// ✅ onAttached callback - element is laid out!
const rect = ref.current.getBoundingClientRect();
console.log(`Width: ${rect.width}, Height: ${rect.height}`);
},
() => {
// onDetached callback (optional)
console.log('Component removed from render tree');
}
);
return <div ref={ref}>Content</div>;
}**Only call these inside onscreen callback or useFlutterAttached:**
const div = document.getElementById('myDiv');
// ❌ WRONG
div.style.width = '500px';
const rect = div.getBoundingClientRect(); // Old dimensions!
// ✅ CORRECT
div.style.width = '500px';
div.addEventListener('onscreen', () => {
const rect = div.getBoundingClientRect(); // New dimensions!
}, { once: true }); // Use 'once' to remove listener after first callfunction showTooltip(targetElement) {
const tooltip = document.createElement('div');
tooltip.className = 'tooltip';
tooltip.textContent = 'Tooltip text';
tooltip.addEventListener('onscreen', () => {
// Now we can safely position the tooltip
const targetRect = targetElement.getBoundingClientRect();
const tooltipRect = tooltip.getBoundingClientRect();
tooltip.style.left = `${targetRect.left}px`;
tooltip.style.top = `${targetRect.bottom + 5}px`;
}, { once: true });
document.body.appendChild(tooltip);
}import { useFlutterAttached } from '@openwebf/react-core-ui';
import { useState } from 'react';
function MeasuredBox() {
const [dimensions, setDimensions] = useState({Repo: openwebf/webf
Check Web API and CSS feature compatibility in WebF - determine what JavaScript APIs, DOM…
Create high-performance infinite scrolling lists with pull-to-refresh and load-more…
Develop custom WebF native plugins based on Flutter packages. Create reusable plugins that…
Install WebF native plugins to access platform capabilities like sharing, payment, camera,…
Develop custom native UI libraries based on Flutter widgets for WebF. Create reusable…
Setup and use WebF's Cupertino UI library to build native iOS-style UIs with pre-built…