cli: [Bug]: --theme-editor-sync running infinite loop

Please confirm that you have:

  • Searched existing issues to see if your issue is a duplicate. (If you’ve found a duplicate issue, feel free to add additional information in a comment on it.)
  • Reproduced the issue in the latest CLI version.

In which of these areas are you experiencing a problem?

Theme

Expected behavior

Running shopify theme dev --store --theme-editor-sync should sync once on start.

Actual behavior

Sync gets stuck in an infinite loop: Screenshot 2024-06-20 at 11 01 23 AM

Verbose output

Sorry, but --verbose runs in an infinite loop when combined with --theme-editor-sync. I'm not exactly sure what to paste here.

Reproduction steps

  1. shopify theme dev --store --theme-editor-sync

Operating System

macOS Sonoma 14.5

Shopify CLI version

3.62.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 22 (3 by maintainers)

Commits related to this issue

Most upvoted comments

+1, same. Seeing infinite loops on settings_schema.json

Oddly, adding a trailing comma to the last item in our settings array in settings_schema.json seems to fix the issue 🤔 (found this clue on another thread)

@shopify/cli/3.59.3 darwin-arm64 node-v22.0.0

image

As a note, something really does need to be done about this, because most code editors these days do auto formatting of files, which does not support the trailing comma as its not part of the spec of JSON. This is causing a massive headache of having to manually copy files when making changes, rather than letting the CLI handle those changes

Thank you for sharing that, @lesterdefreitas! I’ve also noticed a similar scenario here.

My original PR, unfortunately, missed a detail related to assets/* files. The fix for that is applied here, so we may expect that to be resolved in a new CLI release soon.

👋 Hey everyone,

Thank you for your input and all the details about this issue. We’ve released a new version of the Shopify CLI some minutes ago with the fix (3.63.2). Please, if this problem persists, don’t hesitate to reach out and share your --verbose output here.

Thanks again for reporting!

I too have this issue again. I got hundreds of json files going crazy. Impossible to use the CLI like that. It’s been months and still no permanent fix was found, lame!

Here is a node script I placed in a .app folder in my project to add the trailing commas at the end of every json files. Could be better but does the job, and why in the first place do we have to go through this again? Make sure you use git to check the local changes.

const fs = require('fs');
const path = require('path');

// Directories to process
const directories = [
  path.join(__dirname, '../templates'),
  path.join(__dirname, '../locales'),
  path.join(__dirname, '../sections'),
];

function processJsonFile(filePath) {
  fs.readFile(filePath, 'utf8', (err, data) => {
    if (err) {
      console.error(`Error reading file ${filePath}:`, err);
      return;
    }

    // Remove any trailing commas before the final closing brace
    const cleanedData = data.replace(/,\s*([}\]])/g, '$1'); // Removes trailing commas before } or ]

    // Add a comma before the last closing curly brace, if needed
    const modifiedData = cleanedData.replace(/}\s*$/, ',\n}');

    // Write the modified content back to the file
    fs.writeFile(filePath, modifiedData, 'utf8', err => {
      if (err) {
        console.error(`Error writing file ${filePath}:`, err);
      } else {
        console.log(`Updated ${filePath}`);
      }
    });
  });
}

function processDirectory(dir) {
  fs.readdir(dir, { withFileTypes: true }, (err, files) => {
    if (err) {
      console.error(`Error reading directory ${dir}:`, err);
      return;
    }

    files.forEach(file => {
      const filePath = path.join(dir, file.name);
      if (file.isDirectory()) {
        processDirectory(filePath); // Recursively process subdirectories
      } else if (file.isFile() && path.extname(file.name) === '.json') {
        processJsonFile(filePath); // Process JSON file
      }
    });
  });
}

// Process directories
directories.forEach(processDirectory);

this got my Vite assets/manifest.json file too, same endless loop, trailing comma fixed 😕

+1, same issue after updating to 3.62.0