-
Notifications
You must be signed in to change notification settings - Fork 130
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
[Theme] Speed up theme synchronization #4362
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e341344
Delay fetching remote checksums
frandiox 011190e
Delay fetching password
frandiox 5e0fc45
Cleanup
frandiox 1505172
Rename renderThemeSyncProgress
frandiox b603768
Further split files to sync
frandiox cb9a279
Merge branch 'main' into fd-theme-dev-async
frandiox d7bbcc6
Start delete requests earlier and rely on API throttling
frandiox 7c02472
Reuse size info to avoid async code
frandiox 2f45deb
Remove unneeded function
frandiox 2c0c71c
Parallelize uploading file batches
frandiox 8ed8645
Defer deleting files
frandiox e3f82ff
Only defer delete files in server start
frandiox 4437371
Upload dependent files in order
frandiox 4ecd3ad
Do not await for deleteJob to start
frandiox 16ec567
Cleanup
frandiox b8ad836
Fix 404 page
frandiox 6288d6d
More deferring; show progress for theme editor sync
frandiox 4473787
Fix test types
frandiox 733037c
Restore reportFailedUploads
frandiox 3ef4cc3
Merge branch 'main' into fd-theme-dev-async
frandiox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
import {reconcileAndPollThemeEditorChanges} from './remote-theme-watcher.js' | ||
import {DevServerContext} from './types.js' | ||
import {setupDevServer} from './theme-environment.js' | ||
import {render} from './storefront-renderer.js' | ||
import {reconcileAndPollThemeEditorChanges} from './remote-theme-watcher.js' | ||
import {uploadTheme} from '../theme-uploader.js' | ||
import {fakeThemeFileSystem} from '../theme-fs/theme-fs-mock-factory.js' | ||
import {DEVELOPMENT_THEME_ROLE} from '@shopify/cli-kit/node/themes/utils' | ||
import {describe, expect, test, vi} from 'vitest' | ||
import {describe, expect, test, vi, beforeEach} from 'vitest' | ||
import {buildTheme} from '@shopify/cli-kit/node/themes/factories' | ||
import {Response as NodeResponse} from '@shopify/cli-kit/node/http' | ||
import {createEvent} from 'h3' | ||
import {IncomingMessage, ServerResponse} from 'node:http' | ||
import {Socket} from 'node:net' | ||
|
||
vi.mock('@shopify/cli-kit/node/themes/api', () => ({fetchChecksums: () => Promise.resolve([])})) | ||
vi.mock('./remote-theme-watcher.js') | ||
vi.mock('../theme-uploader.js') | ||
vi.mock('./storefront-renderer.js') | ||
|
||
// Vitest is resetting this mock between tests due to a global config `mockReset: true`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't get this working either - Please update me if you figure out another way around this! |
||
// For some reason we need to re-mock it here and in beforeEach: | ||
vi.mock('../theme-uploader.js', async () => { | ||
return { | ||
uploadTheme: vi.fn(() => { | ||
return { | ||
workPromise: Promise.resolve(), | ||
uploadResults: new Map(), | ||
renderThemeSyncProgress: () => Promise.resolve(), | ||
} | ||
}), | ||
} | ||
}) | ||
beforeEach(() => { | ||
vi.mocked(uploadTheme).mockImplementation(() => { | ||
return {workPromise: Promise.resolve(), uploadResults: new Map(), renderThemeSyncProgress: () => Promise.resolve()} | ||
}) | ||
}) | ||
|
||
describe('startDevServer', () => { | ||
const developmentTheme = buildTheme({id: 1, name: 'Theme', role: DEVELOPMENT_THEME_ROLE})! | ||
const localFiles = new Map([ | ||
|
@@ -41,7 +60,6 @@ describe('startDevServer', () => { | |
const localThemeFileSystem = fakeThemeFileSystem('tmp', localFiles) | ||
const defaultServerContext: DevServerContext = { | ||
session: {storefrontToken: '', token: '', storeFqdn: 'my-store.myshopify.com', expiresAt: new Date()}, | ||
remoteChecksums: [], | ||
localThemeFileSystem, | ||
directory: 'tmp', | ||
options: { | ||
|
@@ -63,20 +81,15 @@ describe('startDevServer', () => { | |
} | ||
|
||
// When | ||
await setupDevServer(developmentTheme, context) | ||
await setupDevServer(developmentTheme, context).workPromise | ||
|
||
// Then | ||
expect(uploadTheme).toHaveBeenCalledWith( | ||
developmentTheme, | ||
context.session, | ||
context.remoteChecksums, | ||
context.localThemeFileSystem, | ||
{ | ||
ignore: ['assets/*.json'], | ||
nodelete: true, | ||
only: ['templates/*.liquid'], | ||
}, | ||
) | ||
expect(uploadTheme).toHaveBeenCalledWith(developmentTheme, context.session, [], context.localThemeFileSystem, { | ||
ignore: ['assets/*.json'], | ||
nodelete: true, | ||
only: ['templates/*.liquid'], | ||
deferPartialWork: true, | ||
}) | ||
}) | ||
|
||
test('should initialize theme editor sync if themeEditorSync flag is passed', async () => { | ||
|
@@ -90,13 +103,13 @@ describe('startDevServer', () => { | |
} | ||
|
||
// When | ||
await setupDevServer(developmentTheme, context) | ||
await setupDevServer(developmentTheme, context).workPromise | ||
|
||
// Then | ||
expect(reconcileAndPollThemeEditorChanges).toHaveBeenCalledWith( | ||
developmentTheme, | ||
context.session, | ||
context.remoteChecksums, | ||
[], | ||
context.localThemeFileSystem, | ||
{ | ||
ignore: ['assets/*.json'], | ||
|
@@ -111,19 +124,21 @@ describe('startDevServer', () => { | |
const context = {...defaultServerContext, options: {...defaultServerContext.options, noDelete: true}} | ||
|
||
// When | ||
await setupDevServer(developmentTheme, context) | ||
await setupDevServer(developmentTheme, context).workPromise | ||
|
||
// Then | ||
expect(uploadTheme).toHaveBeenCalledWith(developmentTheme, context.session, [], context.localThemeFileSystem, { | ||
ignore: ['assets/*.json'], | ||
nodelete: true, | ||
only: ['templates/*.liquid'], | ||
deferPartialWork: true, | ||
}) | ||
}) | ||
|
||
describe('request handling', async () => { | ||
const context = {...defaultServerContext} | ||
const {dispatch} = await setupDevServer(developmentTheme, context) | ||
const server = setupDevServer(developmentTheme, context) | ||
|
||
const html = String.raw | ||
const decoder = new TextDecoder() | ||
|
||
|
@@ -154,7 +169,7 @@ describe('startDevServer', () => { | |
return resEnd(content) | ||
} | ||
|
||
await dispatch(event) | ||
await server.dispatchEvent(event) | ||
return {res, status: res.statusCode, body} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't related to the changes in this PR, but this method is hanging / not terminating when I 🎩!
These changes will resolve that issue for us - specifically this commit
Let's make sure that we're able to merge the changes / commit I linked above before the next to avoid breaking
push
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the changes to fix this in your links 🤔
In any case, this problem should be fixed here: e3f82ff
Basically, we only defer the delete job if specified in the function, so that the push command can await for everything. Can you check it? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry - didn't see this. Push and pull are both working properly 👌🏻 !