Performance: Block attributes and controls
MEDIUM IMPACT
This affects page load speed and interaction responsiveness by controlling how block data is stored and updated in the editor and frontend.
const attributes = { content: { type: 'string' } };
function Edit(props) {
const { attributes, setAttributes } = props;
const [localContent, setLocalContent] = React.useState(attributes.content);
React.useEffect(() => {
const timeout = setTimeout(() => setAttributes({ content: localContent }), 300);
return () => clearTimeout(timeout);
}, [localContent]);
return <textarea value={localContent} onChange={e => setLocalContent(e.target.value)} />;
}const attributes = { content: { type: 'string' } };
function Edit(props) {
const { attributes, setAttributes } = props;
return <textarea value={attributes.content} onChange={e => setAttributes({ content: e.target.value })} />;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Immediate attribute update on every input | High (many updates) | High (many reflows) | High (many paints) | [X] Bad |
| Debounced attribute update with local state | Low (fewer updates) | Low (fewer reflows) | Low (fewer paints) | [OK] Good |