Sha256: e84188e1738c0ec8f2e76cafa46011772a5b47437676a1fadfa8694e265f9f0c

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

class HotReload {
  static reloadMode = () => {
    const namespace = window.__SHOPIFY_CLI_ENV__;
    return namespace.mode;
  };
  static isFullPageReloadMode = () => {
    return HotReload.reloadMode() === "full-page";
  };
  static isReloadModeActive = () => {
    return HotReload.reloadMode() !== "off";
  };
  static setHotReloadCookie = (files) => {
    const date = new Date();

    // Hot reload cookie expires in 3 seconds
    date.setSeconds(date.getSeconds() + 3);

    const sections = files.join(",");
    const expires = date.toUTCString();

    document.cookie = `hot_reload_files=${sections}; expires=${expires}; path=/`;
  };
  static refreshPage = (files) => {
    HotReload.setHotReloadCookie(files);
    console.log("[HotReload] Refreshing entire page");
    window.location.reload();
  };
  static isCSSFile = (filename) => {
    return filename.endsWith(".css");
  };
  static reloadCssFile = (filename) => {
    // Find a stylesheet link starting with /assets (locally-served only) containing the filename
    let links = document.querySelectorAll(
      `link[href^="/assets"][href*="${filename}"][rel="stylesheet"]`
    );

    Array.from(links).forEach((link) => {
      if (!link) {
        console.log(
          `[HotReload] Could not find link for stylesheet ${filename}`
        );
      } else {
        link.href = new URL(link.href).pathname + `?v=${Date.now()}`;
        console.log(`[HotReload] Reloaded stylesheet ${filename}`);
      }
    });
  };
}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.35.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.34.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.33.1 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.33.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.32.1 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.32.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.31.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.30.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.29.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.28.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.27.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.26.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js
shopify-cli-2.25.0 lib/shopify_cli/theme/dev_server/hot_reload/resources/hot_reload.js