@@ -771,8 +771,21 @@ function createApp() {
771771 `\x1b[36mℹ Visual Editor API Request: Received ${ changes . length } changes for repo ${ github_repo_name } \x1b[0m`
772772 ) ;
773773
774- // Group changes by file to eliminate duplication
775- const changesByFile = new Map ( ) ;
774+ // Debug: Check if browser dimensions are provided
775+ const changesWithDimensions = changes . filter (
776+ ( change ) => change . browserWidth && change . browserHeight
777+ ) ;
778+ if ( changesWithDimensions . length > 0 ) {
779+ const sampleChange = changesWithDimensions [ 0 ] ;
780+ console . log (
781+ `\x1b[36mℹ Browser dimensions detected: ${ sampleChange . browserWidth } x${ sampleChange . browserHeight } \x1b[0m`
782+ ) ;
783+ } else {
784+ console . log ( `\x1b[33m⚠ No browser dimensions found in changes\x1b[0m` ) ;
785+ }
786+
787+ // Process each change individually to preserve line number information
788+ const fileChangesForBackend = [ ] ;
776789 for ( const change of changes ) {
777790 try {
778791 if ( ! change . encoded_location ) {
@@ -791,28 +804,37 @@ function createApp() {
791804 continue ;
792805 }
793806
794- // Initialize file entry if not exists
795- if ( ! changesByFile . has ( targetFile ) ) {
796- changesByFile . set ( targetFile , {
797- encoded_location : change . encoded_location ,
798- file_content : null , // Will be set below
799- changes : [ ] ,
800- } ) ;
801- }
807+ // Check if this change has actual content
808+ const hasStyleChanges =
809+ change . style_changes && change . style_changes . length > 0 ;
810+ const hasTextChanges =
811+ change . text_changes && change . text_changes . length > 0 ;
802812
803- // Add this element change to the file
804- const elementChange = {
805- style_changes : change . style_changes || [ ] ,
806- text_changes : change . text_changes || [ ] ,
807- } ;
808-
809- // Only add the change if it has actual content
810- if (
811- elementChange . style_changes . length > 0 ||
812- elementChange . text_changes . length > 0
813- ) {
814- changesByFile . get ( targetFile ) . changes . push ( elementChange ) ;
813+ if ( ! hasStyleChanges && ! hasTextChanges ) {
814+ console . warn (
815+ `\x1b[33m⚠ Skipping change with no style or text changes.\x1b[0m`
816+ ) ;
817+ continue ;
815818 }
819+
820+ // Read file content for this specific change
821+ const { fileContent } = readFileFromEncodedLocation (
822+ change . encoded_location
823+ ) ;
824+
825+ // Create individual change entry with its specific encoded_location
826+ fileChangesForBackend . push ( {
827+ encoded_location : change . encoded_location , // Preserve individual encoded_location
828+ file_content : fileContent ,
829+ changes : [
830+ {
831+ style_changes : change . style_changes || [ ] ,
832+ text_changes : change . text_changes || [ ] ,
833+ } ,
834+ ] ,
835+ browser_width : change . browserWidth ,
836+ browser_height : change . browserHeight ,
837+ } ) ;
816838 } catch ( e ) {
817839 console . error (
818840 `\x1b[31m✖ Error processing change for location: ${ change . encoded_location } \x1b[0m`
@@ -827,31 +849,6 @@ function createApp() {
827849 }
828850 }
829851
830- // Read file content for each file and create the grouped structure
831- const fileChangesForBackend = [ ] ;
832- for ( const [ targetFile , fileData ] of changesByFile . entries ( ) ) {
833- try {
834- // Read file content once per file
835- const { fileContent } = readFileFromEncodedLocation (
836- fileData . encoded_location
837- ) ;
838- fileData . file_content = fileContent ;
839-
840- // Only include files that have actual changes
841- if ( fileData . changes . length > 0 ) {
842- fileChangesForBackend . push ( {
843- encoded_location : fileData . encoded_location ,
844- file_content : fileData . file_content ,
845- changes : fileData . changes ,
846- } ) ;
847- }
848- } catch ( error ) {
849- console . error (
850- `\x1b[31m✖ Error reading file content for ${ targetFile } : ${ error . message } \x1b[0m`
851- ) ;
852- }
853- }
854-
855852 if ( fileChangesForBackend . length === 0 ) {
856853 return reply . code ( 200 ) . send ( {
857854 message : "No changes to apply." ,
@@ -860,8 +857,18 @@ function createApp() {
860857 }
861858
862859 console . log (
863- `\x1b[36mℹ Sending grouped request for ${ fileChangesForBackend . length } files with ${ changes . length } total changes\x1b[0m`
860+ `\x1b[36mℹ Sending request for ${ fileChangesForBackend . length } individual changes (${ changes . length } total original changes)\x1b[0m`
861+ ) ;
862+
863+ // Debug: Log browser dimensions being sent to backend
864+ const backendChangesWithDimensions = fileChangesForBackend . filter (
865+ ( change ) => change . browser_width && change . browser_height
864866 ) ;
867+ if ( backendChangesWithDimensions . length > 0 ) {
868+ console . log (
869+ `\x1b[36mℹ Sending browser dimensions to backend for ${ backendChangesWithDimensions . length } changes\x1b[0m`
870+ ) ;
871+ }
865872
866873 const backendResponse = await getChanges ( {
867874 githubRepoName : github_repo_name ,
@@ -894,7 +901,7 @@ function createApp() {
894901 return reply . code ( 200 ) . send ( {
895902 message : `Changes applied successfully to ${
896903 updatedFiles . size
897- } file(s). Processed ${ changes . length } individual changes across ${ fileChangesForBackend . length } files .`,
904+ } file(s). Processed ${ changes . length } individual changes with preserved line number information .`,
898905 updatedFiles : Array . from ( updatedFiles ) ,
899906 } ) ;
900907 } catch ( err ) {
0 commit comments