Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Themes] Theme Dev - Editor Sync - Fix Hanging Theme Reconciliation Progress Bar and User Inputs #4392

Merged
merged 6 commits into from
Sep 2, 2024

Conversation

jamesmengo
Copy link
Contributor

@jamesmengo jamesmengo commented Aug 28, 2024

WHY are these changes introduced?

WHAT is this pull request doing?

  • Adds the theme reconciliation progress bar back
    • Fixes an issue where the progress bar would render before the user has a chance to provide input - rendering the CLI in a "stuck" state where input there is no way to provide the input needed to resolve the progress bar
  • Fixes an async conflict with the store-password input which prevented users from selecting a reconciliation option

How to test your changes?

  1. Checkout the latest version of Dawn
  2. Upload this version of Dawn to your shop using shopify theme push -d.
    This will trigger a job on core which adds settings keys in your JSON assets
  3. Run shopify-dev theme dev --dev-preview --theme-editor-sync --store-password=<INCORRECT_PASSWORD>.
    You should see a large number of JSON files listed.
  4. Select 'Keep the remote version`.
  5. Verify the following:
  • you were able to select an option for reconciliation
  • the progress bar should only render AFTER that
  • progress bar should terminate once your reconciliation is completed

Code - Dawn

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

@jamesmengo jamesmengo added the #gsd:40767 Fortify local development experience for Liquid themes label Aug 28, 2024
@jamesmengo jamesmengo self-assigned this Aug 28, 2024
@jamesmengo jamesmengo marked this pull request as ready for review August 28, 2024 22:46
Copy link
Contributor

We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset.
If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

Copy link
Contributor

github-actions bot commented Aug 28, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.86% (+0.11% 🔼)
8266/11345
🟡 Branches
69.47% (+0.07% 🔼)
4036/5810
🟡 Functions
71.56% (+0.03% 🔼)
2156/3013
🟡 Lines
73.2% (+0.12% 🔼)
7819/10681

Test suite run success

1862 tests passing in 845 suites.

Report generated by 🧪jest coverage report action from 9fb98ce

Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! I had no idea that --theme-editor-sync required prompts, I would have done things differently in other PRs if I knew it 😅

Looking at the changes, I think we're going to have a race condition between the Theme Sync prompts and the Password prompt (or any other prompt we add in the future).

Generally speaking, we shouldn't have 2 different background tasks that render things to the terminal. That's why it's a good idea to separate background work from prompts / loading bars.

I think it's hard to fix this issue in the theme editor sync right now, so perhaps easier to change how the password thing works? We'd need to await for its prompt after all the setup is done but before starting the server. I guess we can refactor all of this later and try to find a better flow.

Aside from that, I'm leaving a comment below for different things.

Comment on lines 32 to 40
const {reconciliationFinishedPromise, readyForReconciliationPromise} = await reconcileJsonFiles(
targetTheme,
session,
remoteChecksums,
localThemeFileSystem,
options,
)

const updatedRemoteChecksums = await fetchChecksums(targetTheme.id, session)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is now async, I don't think updatedRemoteChecksums is actually getting the updated ones?

Can we make up the updatedRemoteChecksums variable with the information we already have after the prompts? Merging actual remote checksums + checksums we have locally that we are going to update?

Comment on lines 51 to 64
await performFileReconciliation(targetTheme, session, localThemeFileSystem, partitionedFiles)
const reconciliationFinishedPromise = readyForReconciliationPromise.then((partitionedFiles) =>
performFileReconciliation(targetTheme, session, localThemeFileSystem, partitionedFiles),
)

return {
readyForReconciliationPromise: readyForReconciliationPromise.then(() => {}),
reconciliationFinishedPromise,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to calculate updated remote checksums, perhaps we should keep the prompting here upfront, since there's nothing else we can do without this information.

const partitionedFiles = await partitionFilesByReconciliationStrategy(...)

...

return { workPromise: performFileReconciliation(targetTheme, session, localThemeFileSystem, partitionedFiles) }


const themeSetupPromise = editorSyncPromise.then(
({updatedRemoteChecksums, reconciliationFinishedPromise, readyForReconciliationPromise}) => {
const uploadPromise = reconciliationFinishedPromise.then(() =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get the updatedRemoteChecksums (fabricated locally), I don't think we need to await for reconciliationFinishedPromise? That work is just downloading files, and we can start uploading in parallel, right? Or am I missing something 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! We wait for the download to finish to prevent a race condition between this scenario
-> Download changes on sections/example.json from remote theme
-> At the same time, we may upload our local version of sections/example.json if the fileSystem hasn't been updated yet

Copy link
Contributor

@karreiro karreiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR, @jamesmengo!

We may adopt the following steps to understand the initialization issue we're facing with the reconciliation:

# Open Dawn
$ dev cd dawn

# Let's go to and older version
$ git reset origin/v11.0.0 --hard

# Push that version to our remote development theme
$ shopify theme push -d

# Pull the remote version so we may download the missing "settings" keys that Core adds in some files
$ shopify theme pull -d

# Run:
$ shopify theme dev --dev-preview --theme-editor-sync

We will get these logs:


dawn$ shopify theme dev --dev-preview --theme-editor-sync
This feature is currently in development and is not ready for use or testing yet.
╭─ info ───────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  The files listed below are only present locally. What would you like to do?                         │
│    • locales/bg.json                                                                                 │
│    • locales/hr.json                                                                                 │
│    • locales/lt.json                                                                                 │
│    • locales/ro.json                                                                                 │
│    • locales/sk.json                                                                                 │
│    • locales/sl.json                                                                                 │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

?  Reconciliation Strategy:
✔  Delete files from the local directory

╭─ info ───────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  The files listed below are only present on the remote theme. What would you like to do?             │
│    • locales/bg-BG.json                                                                              │
│    • locales/hr-HR.json                                                                              │
│    • locales/lt-LT.json                                                                              │
│    • locales/ro-RO.json                                                                              │
│    • locales/sk-SK.json                                                                              │
│    • locales/sl-SI.json                                                                              │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

?  Incorrect password provided. Please try again:
✔  *****

╭─ info ───────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  The files listed below differ between the local and remote versions. What would you like to do?     │
│    • config/settings_data.json                                                                       │
│    • config/settings_schema.json                                                                     │
│    • locales/cs.json                                                                                 │
│    • locales/cs.schema.json                                                                          │
│    • locales/da.json                                                                                 │
│    • locales/da.schema.json                                                                          │
│    • locales/de.json                                                                                 │
│    • locales/de.schema.json                                                                          │
│    • locales/el.json                                                                                 │
│    • locales/en.default.json                                                                         │
│    • locales/en.default.schema.json                                                                  │
│    • locales/es.json                                                                                 │
│    • locales/es.schema.json                                                                          │
│    • locales/fi.json                                                                                 │
│    • locales/fi.schema.json                                                                          │
│    • locales/fr.json                                                                                 │
│    • locales/fr.schema.json                                                                          │
│    • locales/hu.json                                                                                 │
│    • locales/id.json                                                                                 │
│    • locales/it.json                                                                                 │
│    • locales/it.schema.json                                                                          │
│    • locales/ja.json                                                                                 │
│    • locales/ja.schema.json                                                                          │
│    • locales/ko.json                                                                                 │
│    • locales/ko.schema.json                                                                          │
│    • locales/nb.json                                                                                 │
│    • locales/nb.schema.json                                                                          │
│    • locales/nl.json                                                                                 │
│    • locales/nl.schema.json                                                                          │
│    • locales/pl.json                                                                                 │
│    • locales/pl.schema.json                                                                          │
│    • locales/pt-BR.json                                                                              │
│    • locales/pt-BR.schema.json                                                                       │
│    • locales/pt-PT.json                                                                              │
│    • locales/pt-PT.schema.json                                                                       │
│    • locales/ru.json                                                                                 │
│    • locales/sv.json                                                                                 │
│    • locales/sv.schema.json                                                                          │
│    • locales/th.json                                                                                 │
│    • locales/th.schema.json                                                                          │
│    • locales/tr.json                                                                                 │
│    • locales/tr.schema.json                                                                          │
│    • locales/vi.json                                                                                 │
│    • locales/vi.schema.json                                                                          │
│    • locales/zh-CN.json                                                                              │
│    • locales/zh-CN.schema.json                                                                       │
│    • locales/zh-TW.json                                                                              │
│    • locales/zh-TW.schema.json                                                                       │
│    • sections/footer-group.json                                                                      │
│    • sections/header-group.json                                                                      │
│    • templates/404.json                                                                              │
│    • templates/article.json                                                                          │
│    • templates/cart.json                                                                             │
│    • templates/collection.json                                                                       │
│    • templates/customers/account.json                                                                │
│    • templates/customers/activate_account.json                                                       │
│    • templates/customers/addresses.json                                                              │
│    • templates/customers/login.json                                                                  │
│    • templates/customers/order.json                                                                  │
│    • templates/customers/register.json                                                               │
│    • templates/customers/reset_password.json                                                         │
│    • templates/index.json                                                                            │
│    • templates/page.contact.json                                                                     │
│    • templates/password.json                                                                         │
│    • templates/product.json                                                                          │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

?  Incorrect password provided. Please try again:
✔  ******

╭─ success ────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  Preview your theme                                                                                  │
│    • http://127.0.0.1:9292                                                                           │
│                                                                                                      │
│  Next steps                                                                                          │
│    • Customize your theme at the theme editor                                                        │
│    • Share your theme preview                                                                        │
│      (https://cheap-comic-strip-com.myshopify.com/?preview_theme_id=163762274326)                    │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

╭─ warning ────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  Failed to delete file "locales/ro.json".                                                            │
│                                                                                                      │
│  Unknown issue.                                                                                      │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

╭─ warning ────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  Failed to delete file "locales/hr.json".                                                            │
│                                                                                                      │
│  Unknown issue.                                                                                      │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

╭─ warning ────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  Failed to delete file "locales/lt.json".                                                            │
│                                                                                                      │
│  Unknown issue.                                                                                      │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

• 10:37:06 Synced » download templates/404.json from remote theme
• 10:37:06 Synced » download templates/article.json from remote theme
• 10:37:06 Synced » download templates/cart.json from remote theme
• 10:37:06 Synced » download sections/header-group.json from remote theme
╭─ warning ────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  Failed to delete file "locales/bg.json".                                                            │
│                                                                                                      │
│  Unknown issue.                                                                                      │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

╭─ warning ────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  Failed to delete file "locales/sl.json".                                                            │
│                                                                                                      │
│  Unknown issue.                                                                                      │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

╭─ warning ────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│  Failed to delete file "locales/sk.json".                                                            │
│                                                                                                      │
│  Unknown issue.                                                                                      │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯

• 10:37:07 Synced » download templates/customers/activate_account.json from remote theme
• 10:37:07 Synced » download templates/customers/account.json from remote theme
• 10:37:07 Synced » download templates/password.json from remote theme
• 10:37:07 Synced » download templates/index.json from remote theme
• 10:37:07 Synced » download templates/product.json from remote theme
• 10:37:11 Synced » download templates/customers/addresses.json from remote theme
• 10:37:11 Synced » download config/settings_schema.json from remote theme
• 10:37:16 Synced » update config/settings_schema.json
• 10:37:17 Synced » download templates/customers/login.json from remote theme
• 10:37:18 Synced » download templates/customers/order.json from remote theme
• 10:37:21 Synced » download templates/customers/register.json from remote theme
• 10:37:21 Synced » download templates/customers/reset_password.json from remote theme

@jamesmengo jamesmengo force-pushed the jm/editorsyncprogress branch 3 times, most recently from ce8e7ca to 58e0307 Compare August 31, 2024 00:17
@jamesmengo jamesmengo changed the title [Themes] Theme Dev - Editor Sync - Fix Hanging Theme Reconciliation Progress Bar [Themes] Theme Dev - Editor Sync - Fix Hanging Theme Reconciliation Progress Bar and User Inputs Aug 31, 2024
@@ -53,34 +60,6 @@ describe('reconcileAndPollThemeEditorChanges', async () => {
)
})

test('should not call reconcileJsonFiles when remote theme contains no files', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test and logic moved to theme-reconciliation

@jamesmengo jamesmengo marked this pull request as ready for review August 31, 2024 01:41
Copy link
Contributor

@karreiro karreiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @jamesmengo!

@karreiro karreiro dismissed frandiox’s stale review September 2, 2024 11:29

Fran is OOO this week, and James has updated the PR accordingly :)

@karreiro
Copy link
Contributor

karreiro commented Sep 2, 2024

I've raised an issue here that was revealed by this PR but isn't directly related. So, we're proceeding with the merge 🚀

@karreiro karreiro added this pull request to the merge queue Sep 2, 2024
Merged via the queue into main with commit 02cfec7 Sep 2, 2024
37 checks passed
@karreiro karreiro deleted the jm/editorsyncprogress branch September 2, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#gsd:40767 Fortify local development experience for Liquid themes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants