5.2 KiB
MyUIbrix Viewport and Style Changes Fix
Issues Identified
1. Blank First Section
Problem: The viewport wrapper was targeting .chakra-container which wraps both the navigation AND the page content. This caused:
- Two viewport wrappers being created (one for nav, one for content)
- Navigation elements appearing in a blank section
- Page content appearing below in a separate wrapper
Root Cause: MainLayout uses <Container maxW="container.xl"> (Chakra component) which renders as .chakra-container. HomePage has its own .container div inside this Chakra Container. MyUIbrix was wrapping the Chakra Container's children instead of the specific .container div.
Solution: Updated MyUIbrixEditor.tsx (lines 1154-1198) to:
- Target
.containerspecifically instead of.chakra-container - Move children from
.containerinto the viewport wrapper - Keep the wrapper INSIDE
.containerinstead of replacing it - Preserve the DOM structure that React expects
2. Style Changes Not Working
Problem: Style changes from VisualStylePanel weren't being applied to elements.
Root Cause: The applyDOMOrder function in usePageElementConfig.ts was looking for elements in .container, but when MyUIbrix is active, elements are inside .myuibrix-viewport-wrapper which is inside .container.
Solution: Updated usePageElementConfig.ts (lines 49-53) to:
- Check for
.myuibrix-viewport-wrapperfirst - Fall back to
.containerif wrapper doesn't exist - This ensures element queries work in both edit and non-edit modes
Files Modified
1. /frontend/src/components/editor/MyUIbrixEditor.tsx
Lines 1154-1198: Updated viewport wrapper creation
- Changed from targeting
.chakra-containerto.container - Modified DOM manipulation to work within
.container - Wrapper now stays inside
.containerparent
Lines 1200-1237: Updated viewport wrapper removal
- Added check for
wrapper.parentElement === pageContainer - Proper restoration of original container structure
- Fixed Chakra Container style restoration
Lines 1239-1275: Updated cleanup function
- Same improvements as removal logic
- Ensures proper cleanup on unmount
2. /frontend/src/hooks/usePageElementConfig.ts
Lines 49-69: Updated applyDOMOrder function
- Checks for
.myuibrix-viewport-wrapperfirst - Falls back to
.containerwhen wrapper doesn't exist - Ensures element reordering works in edit mode
How It Works Now
Edit Mode Activation
- User clicks edit button
- MyUIbrix finds
.containerdiv (the homepage content container) - Creates
.myuibrix-viewport-wrapperdiv - Moves all children from
.containerinto wrapper - Appends wrapper back into
.container - Expands Chakra Container to full width for proper preview
Style Changes
- User changes style in VisualStylePanel
- VisualStylePanel calls
onStyleChange(newStyles) - MyUIbrixEditor's
handleStyleChangeupdates state - After 100ms debounce, dispatches
myuibrix-style-changeevent usePageElementConfighook catches event, updates styles state- Hook now correctly finds elements inside
.myuibrix-viewport-wrapper - HomePage re-renders with
...getStyles('elementName') - React applies new inline styles to elements
Structure Comparison
Before (broken):
.chakra-container (targeted by MyUIbrix)
.myuibrix-viewport-wrapper
Navigation elements (wrong!)
.container
.myuibrix-viewport-wrapper
Page content (separate wrapper!)
After (fixed):
.chakra-container (not touched by MyUIbrix)
Navigation (stays here)
.container (page content wrapper)
.myuibrix-viewport-wrapper
<all page sections>
Testing Checklist
- MyUIbrix editor activates without errors
- No blank sections appear
- All page content visible in editor
- Viewport switching works (desktop/tablet/mobile)
- Clicking on elements shows style panel
- Style changes apply immediately (100ms debounce)
- Typography changes work
- Color changes work
- Spacing changes work
- Layout changes work
- Element reordering works
- Element visibility toggle works
- Exiting editor restores original layout
- No console errors during edit or exit
Style Flow Verification
To verify styles are working:
- Activate MyUIbrix editor
- Click on any section (e.g., "hero")
- Open VisualStylePanel (should appear automatically)
- Change background color
- Expected: Color changes immediately with 100ms delay
- Change padding/margin
- Expected: Spacing updates immediately
- Exit editor
- Expected: Changes not saved (preview only)
- Re-activate editor, make change, click "Publikovat"
- Expected: Changes saved to database
Known Limitations
- Direct DOM manipulation still used (necessary for viewport wrapper)
- React must re-render to apply styles (happens automatically via state)
- 100ms debounce on style changes to prevent lag
- Wrapper only works with
.containerdiv (homepage specific)
Future Improvements
- Consider using React portal instead of direct DOM manipulation
- Add transition animations when styles change
- Implement undo/redo for style changes
- Add keyboard shortcuts for common style adjustments
- Support for other page types beyond homepage