Skip to content

Commit

Permalink
Fix initial draft update (#4929)
Browse files Browse the repository at this point in the history
### WHY are these changes introduced?

Addresses potential race conditions when pushing updates for draftable extensions in parallel.

### WHAT is this pull request doing?

- Filters extension events to only process draftable extensions
- Implements concurrent processing of extension updates using `Promise.all`

### How to test your changes?

1. Run dev with multiple draftable extensions (admin-action, theme)
2. Verify that we send initial drafts for every extension. 

### Measuring impact

- [x] n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

### Checklist

- [x] I've considered possible cross-platform impacts (Mac, Linux, Windows)
- [x] I've considered possible [documentation](https://shopify.dev) changes
  • Loading branch information
isaacroldan authored Nov 27, 2024
2 parents 6a80215 + 0da3319 commit 55eef10
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,23 @@ export const pushUpdatesForDraftableExtensions: DevProcessFunction<DraftableExte
// as it might be done multiple times in parallel. https://github.com/Shopify/cli/issues/2877
await installJavy(app)

const draftableExtensions = app.draftableExtensions.map((ext) => ext.handle)

async function refreshToken() {
await developerPlatformClient.refreshToken()
}

const handleAppEvent = (event: AppEvent) => {
const handleAppEvent = async (event: AppEvent) => {
const extensionEvents = event.extensionEvents
.filter((ev) => ev.type === EventType.Updated)
.filter((ev) => ev.buildResult?.status === 'ok')
.filter((ev) => draftableExtensions.includes(ev.extension.handle))

for (const extensionEvent of extensionEvents) {
const promises = extensionEvents.map(async (extensionEvent) => {
const extension = extensionEvent.extension
const registrationId = remoteExtensions[extension.localIdentifier]
if (!registrationId) throw new AbortError(`Extension ${extension.localIdentifier} not found on remote app.`)
return useConcurrentOutputContext({outputPrefix: extension.outputPrefix}, async () => {
await useConcurrentOutputContext({outputPrefix: extension.outputPrefix}, async () => {
return performActionWithRetryAfterRecovery(
async () =>
updateExtensionDraft({
Expand All @@ -62,7 +65,8 @@ export const pushUpdatesForDraftableExtensions: DevProcessFunction<DraftableExte
refreshToken,
)
})
}
})
await Promise.all(promises)
}

appWatcher.onEvent(handleAppEvent).onStart(handleAppEvent)
Expand Down

0 comments on commit 55eef10

Please sign in to comment.