2.5 KiB
2.5 KiB
Project Hints and Findings
Properties Panel Element Detection Issue (Fixed)
Problem
The properties panel had timing issues detecting rendered elements because:
- Elements are rendered asynchronously via lit's
render()
function in the dashboard component - The properties panel tried to find elements immediately without waiting for render completion
- Element search only looked at direct children of the viewport, missing nested elements or those inside shadow DOM
Solution Implemented
- Added a 100ms initial delay to allow render completion
- Implemented recursive element search that:
- Searches through nested children up to 5 levels deep
- Checks shadow roots of elements
- Handles complex DOM structures
- Added retry mechanism with up to 5 attempts (200ms between retries)
- Improved error messages to show retry count
Code Flow
- Dashboard renders element demo into viewport using
render(anonItem.demo(), viewport)
- Properties panel waits, then searches recursively for the element instance
- If not found, retries with delays to handle async rendering
- Once found, extracts and displays element properties
Demo Tools
DeesDemoWrapper Component
A utility component for wrapping demo elements with post-render functionality.
Usage:
import * as demoTools from '@design.estate/dees-wcctools/demotools';
// In your demo function:
demo: () => html`
<dees-demowrapper .runAfterRender=${(wrapper) => {
// Use querySelector for specific elements
const myElement = wrapper.querySelector('my-custom-element');
myElement?.setAttribute('data-demo', 'true');
// Access all children
console.log('All children:', wrapper.children);
// Use querySelectorAll for multiple elements
wrapper.querySelectorAll('div').forEach(div => {
console.log('Found div:', div);
});
// Full DOM API available
const firstChild = wrapper.firstElementChild;
const hasClass = wrapper.querySelector('.my-class');
}}>
<my-custom-element></my-custom-element>
<div>Additional content</div>
</dees-demowrapper>
`
Features:
- Wraps demo elements without affecting layout (uses
display: contents
) - Provides the wrapper element itself with full DOM API access
- Use querySelector/querySelectorAll for powerful element selection
- Access children via wrapper.children property
- Supports async operations in runAfterRender callback
- Automatically handles timing to ensure elements are fully rendered