Shopify / Shopify/theme-tools

docs-updater should race against a timeout or else starting the language server hangs.

Open
#21 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

tech debt
Dominant language
TypeScript
Stars
234
Forks
92
Avg merge
1d 3h
Merged PRs (30d)
6

Description

Describe the bug
The VS Code extension hangs if you start it with Wifi down (happened to me during storms last week). It hangs because theme-docs-updater attempts to download latest.json from theme-liquid-docs and it doesn't timeout (or the timeout is long).

We should do something more along the lines of "wait at most 5s and otherwise go with what is on disk".

Something like this:

const timeout = (ms: number) => new Promise((_, reject) => setTimeout(reject, ms));

  /**
   * The setup method checks that the latest revision matches the one from
   * Shopify/theme-liquid-docs. If there's a diff in revision, it means
   * that the documentations that you have locally are out of date.
   *
   * The setup method then downloads the other files.
   */
  setup = memo(async (): Promise<void> => {
    if (!(await exists(root))) {
      await fs.mkdir(root, { recursive: true });
    }

    const local = await this.latestRevision();
    try {
      await Promise.race([download('latest'), timeout(2000)]);
      const remote = await this.latestRevision();
      if (local !== remote) {
        await Promise.all(Resources.map((resource) => download(resource)));
      }
    } catch (_) {
      // we're offline...
    }
  });

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the theme-docs-updater setup method and inspect its latestRevision and download calls. Reproduce startup with Wi-Fi unavailable, then verify that it proceeds using on-disk documentation after at most the requested timeout instead of hanging.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, devtools
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.