@@ -2,7 +2,6 @@ import { Codegen } from '../Codegen'
22import { renderComponent , renderNode } from '../render'
33import type { NodeTree , Props } from '../types'
44import {
5- BREAKPOINT_INDEX ,
65 type BreakpointKey ,
76 getBreakpointByWidth ,
87 mergePropsToResponsive ,
@@ -212,34 +211,18 @@ export class ResponsiveCodegen {
212211 }
213212
214213 if ( childByBreakpoint . size > 0 ) {
215- // Add display:none props when a child exists only at specific breakpoints
216- // Find the smallest breakpoint where child exists
217- const sortedPresentBreakpoints = [ ...presentBreakpoints ] . sort (
218- ( a , b ) => BREAKPOINT_INDEX [ a ] - BREAKPOINT_INDEX [ b ] ,
219- )
220- const smallestPresentBp = sortedPresentBreakpoints [ 0 ]
221- const smallestPresentIdx = BREAKPOINT_INDEX [ smallestPresentBp ]
222-
223- // Find the smallest breakpoint in the section
224- const sortedSectionBreakpoints = [ ...treesByBreakpoint . keys ( ) ] . sort (
225- ( a , b ) => BREAKPOINT_INDEX [ a ] - BREAKPOINT_INDEX [ b ] ,
226- )
227- const smallestSectionBp = sortedSectionBreakpoints [ 0 ]
228- const smallestSectionIdx = BREAKPOINT_INDEX [ smallestSectionBp ]
229-
230- // If child's smallest breakpoint is larger than section's smallest,
231- // we need to add display:none for the smaller breakpoints
232- if ( smallestPresentIdx > smallestSectionIdx ) {
233- // Add display:none for all breakpoints smaller than where child exists
234- for ( const bp of treesByBreakpoint . keys ( ) ) {
235- if ( ! presentBreakpoints . has ( bp ) ) {
236- const firstChildTree = [ ...childByBreakpoint . values ( ) ] [ 0 ]
237- const hiddenTree : NodeTree = {
238- ...firstChildTree ,
239- props : { ...firstChildTree . props , display : 'none' } ,
240- }
241- childByBreakpoint . set ( bp , hiddenTree )
214+ // Add display:none props for breakpoints where child doesn't exist
215+ // This handles both:
216+ // 1. Child exists only in mobile (needs display:none in pc)
217+ // 2. Child exists only in pc (needs display:none in mobile)
218+ for ( const bp of treesByBreakpoint . keys ( ) ) {
219+ if ( ! presentBreakpoints . has ( bp ) ) {
220+ const firstChildTree = [ ...childByBreakpoint . values ( ) ] [ 0 ]
221+ const hiddenTree : NodeTree = {
222+ ...firstChildTree ,
223+ props : { ...firstChildTree . props , display : 'none' } ,
242224 }
225+ childByBreakpoint . set ( bp , hiddenTree )
243226 }
244227 }
245228
0 commit comments