AI summary by TwinMind
How did this not exist before???
Theo - t3․gg
9m 28s
Browser Element Movement Limitations
- Browser currently cannot move elements from one place to another
- Only option: delete element in one place and recreate elsewhere
- This breaks functionality for various reasons
- New DOM.moveBefore API will solve this problem
Sponsor Segment
- Over 50% of React devs come to channel for modern tools/technologies
- 75%+ of audience is 25+ years old
- Multiple sponsors saw 3x-10x growth in new signups from single video
- Contact: YouTube@T3 for sponsorship opportunities
- End of year sale currently running
Demo Page Examples (Current Browser)
- Demo created to show flag working in Arc (Chromium-based)
- Not on latest Chrome Canary, so feature not available
- Dialog element example:
- Opens as modal at top of page (web standard)
- When reparented, breaks browser state
- No longer functions as modal, appears inline instead
- iframe example:
- YouTube music video playing
- When reparented, loses state completely
- Stops playing because element deleted/recreated
Chrome Canary Demo (With New API)
- Dialog maintains modal state when reparented
- iframe (Rick Roll video) continues playing after reparent
- State preservation works across element moves
ModView Tool Case Study
- Built at Twitch with small team of talented devs
- Everything customizable - can move chat to different positions
- Chat maintains state: messages, history preserved during moves
- Traditional React approach would lose all state on element moves
- Video players would break terribly when moved
React Portal Workaround Solution
- Used React portal primitive as hack
- Render elements in virtual DOM in one place
- Change real DOM location later
- Changing where React code outputs vs changing element position
- Complex to build, not fun to implement
- New APIs make this unnecessary
Sebastian Lorber Credit
- Got information from Sebastian on Blue Sky
- Should follow him on Blue Sky
- Called out that this would find way into React
React Integration
- Already merged as experiment in React
- Long-standing issue: reordering stateful nodes lose state
- MoveBefore proposal moved to "intent to ship"
- Function similar to insertBefore but preserves state
- Demo available, ideally port to fixture for testing
Impact on React Development
- Main reason for using portals goes away
- Dialog killing need for portals with z-index
- MoveBefore killing need to maintain state externally
- Need for portals decreasing massively
- Browser should focus on making frameworks need fewer hacks
HTMX Integration
- HTMX already added this feature
- Makes sense for HTMX - move elements without pulling full framework
- Can move elements around without losing anything
Additional Examples and Edge Cases
- Input field example:
- Typing "sub nerds please sub"
- Press enter triggers reparent
- Loses focus because element deleted/recreated
- Focus/blur state part of element state
- Current implementation: if event.key === enter, prevent default, remove input, move elsewhere
- Removing focused element kills focus state
Full Screen Element Example
- Full screen element breaks when parent changes
- No longer full screen, must request again
- Chrome Canary: can reparent while maintaining full screen state
Accessibility Considerations
- Chat concerns about accessibility impact
- Argument: losing focus often less intuitive for users
- Screen reader example: layout shifts but user mid-input
- Losing focus less intuitive when can't see screen shifting
- Browser primitive makes it easier to do right thing for users
- Accessibility approach: follow standards, be open to input
- Most important: team should be reachable for accessibility problems
- Features make it easier to solve reported problems
- More tools for solving user problems regardless of specific needs
