Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ jobs:
with:
path: ./storybook-static
- run: npm publish
if: github.event_name == 'release' && github.event.action == 'created'
#if: github.event_name == 'release' && github.event.action == 'created'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
50 changes: 50 additions & 0 deletions src/vanilla/makecode-frame-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ export class MakeCodeFrameDriver {
return;
}

// The 'newproject' host message (sent when started with noproject=1) currently arrives
// without a 'type' field — every other postHostMessageAsync call site in MakeCode sets
// type: 'pxthost' but app.tsx:6519 doesn't. Match on action and tolerate either shape so
// we keep working if upstream is fixed.
// Treat it as a readiness signal so the import reply can flush the queue without waiting
// for editorcontentloaded (which itself only fires after a project loads).
if (
data.action === 'newproject' &&
(!data.type || data.type === 'pxthost')
) {
this.ready = true;
this.messageQueue.forEach((m) => this.sendMessageNoReadyCheck(m));
this.messageQueue.length = 0;
this.handleNewProjectRequest();
return;
}

// I think 'editorcontentloaded' isn't useful here in controller scenarios but needs confirming.
// Might be the right option when waiting to render blocks or similar?
if (
Expand Down Expand Up @@ -356,6 +373,30 @@ export class MakeCodeFrameDriver {
this.iframe()?.contentWindow?.postMessage(message, '*');
};

private async handleNewProjectRequest() {
try {
const projects = await this.options.initialProjects();
if (projects.length > 0) {
const { filters, searchBar } = this.options;
this.sendMessageNoReadyCheck({
type: 'pxteditor',
action: 'importproject',
project: projects[0],
filters,
searchBar,
} as EditorMessageImportProjectRequest);
} else {
this.sendMessageNoReadyCheck({
type: 'pxteditor',
action: 'newproject',
options: { preferredEditor: 'blocksprj' },
} as EditorMessageNewProjectRequest);
}
} catch (e) {
console.error(e);
}
}

private async handleWorkspaceSync(
event: EditorWorkspaceSyncRequest | EditorWorkspaceSaveRequest
) {
Expand Down Expand Up @@ -830,6 +871,15 @@ export const createMakeCodeURL = (
}
if (controller) {
url.searchParams.set('controller', controller.toString());
// TEMPORARY: skip MakeCode's racy auto-default-project step. The driver
// responds to the resulting 'newproject' host message by importing
// initialProjects()[0]. Workaround for the race fixed by
// https://github.com/microsoft/pxt/commit/50486a92c909a56c1270a9c549aa483bbe1d74bd
// (issue https://github.com/microsoft/pxt-microbit/issues/6081). Trades
// the race for a brief loading-dimmer flash, so REMOVE this and the
// associated 'newproject' handler once that fix is live in the deployed
// MakeCode.
url.searchParams.set('noproject', '1');
}
if (queryParams) {
for (const [k, v] of Object.entries(queryParams)) {
Expand Down
Loading