Skip to content

Commit 35ba22b

Browse files
committed
Update current development theme on create OR find
Now that developers can create additional development themes with the `--development-context` flag we should make sure we're always setting the current development theme to the one that was most recently used.
1 parent 9a39b44 commit 35ba22b

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

.changeset/every-years-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/cli-kit': patch
3+
---
4+
5+
Set the current theme in local development on create or find

packages/cli-kit/src/public/node/themes/theme-manager.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe('ThemeManager', () => {
6868
expect(fetchTheme).toHaveBeenCalledWith(123, session)
6969
expect(result).toEqual(mockTheme)
7070
expect(themeCreate).not.toHaveBeenCalled()
71+
expect(manager.getStoredThemeId()).toBe('123')
7172
})
7273

7374
test('creates a new theme when one does not exist', async () => {
@@ -105,6 +106,7 @@ describe('ThemeManager', () => {
105106
expect(findDevelopmentThemeByName).toHaveBeenCalledWith('Dev', session)
106107
expect(result).toEqual(mockTheme)
107108
expect(themeCreate).not.toHaveBeenCalled()
109+
expect(manager.getStoredThemeId()).toBe('123')
108110
})
109111
})
110112

packages/cli-kit/src/public/node/themes/theme-manager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export abstract class ThemeManager {
1515

1616
async findOrCreate(name?: string, role?: Role): Promise<Theme> {
1717
let theme = await this.fetch(name, role)
18-
if (!theme) {
18+
if (theme) {
19+
this.setTheme(theme.id.toString())
20+
} else {
1921
theme = await this.create(role, name)
2022
}
2123
return theme
@@ -29,8 +31,7 @@ export abstract class ThemeManager {
2931
const theme =
3032
name && role === DEVELOPMENT_THEME_ROLE
3133
? await findDevelopmentThemeByName(name, this.adminSession)
32-
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
33-
await fetchTheme(parseInt(this.themeId!, 10), this.adminSession)
34+
: await fetchTheme(parseInt(this.themeId!, 10), this.adminSession)
3435

3536
if (!theme) {
3637
this.removeTheme()

0 commit comments

Comments
 (0)