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

Fix shopify theme dev issue to avoid previewing the live theme instead of the development one #3471

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-goats-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Fix `shopify theme dev` issue to avoid previewing the live theme instead of the development one
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ class Proxy
wpm
]

def initialize(ctx, theme, param_builder)
def initialize(ctx, theme, param_builder, cache_cleaned = false)
@ctx = ctx
@theme = theme
@param_builder = param_builder
@cache_cleaned = cache_cleaned

@core_endpoints = Set.new
@secure_session_id = nil
Expand All @@ -56,6 +57,9 @@ def call(env)
headers["User-Agent"] = "Shopify CLI"
query = URI.decode_www_form(env["QUERY_STRING"])
replace_templates = build_replacement_param(env)

clean_sfr_cache(env, query, headers)

response = if replace_templates.any?
# Pass to SFR the recently modified templates in `replace_templates` or
# `replace_extension_templates` body param
Expand Down Expand Up @@ -101,6 +105,22 @@ def secure_session_id

private

def clean_sfr_cache(env, query, headers)
return if @cache_cleaned

@cache_cleaned = true

query = query.dup
query << ["preview_theme_id", theme_id]

request(
env["REQUEST_METHOD"], env["PATH_INFO"],
headers: headers,
query: query,
body_stream: (env["rack.input"] if has_body?(headers))
)
end

def patch_body(env, body)
return [""] unless body

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setup
.with_theme(@theme)
.with_syncer(@syncer)

@proxy = Proxy.new(@ctx, @theme, param_builder)
@proxy = Proxy.new(@ctx, @theme, param_builder, true)
end

def test_get_is_proxied_to_online_store
Expand Down