Skip to content

Unblock apps to call dialog.url.submit in mobile #2788

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

Merged
merged 5 commits into from
May 14, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Unblocked apps on Mobile to call `dialog.url.submit` from dialog by allowing this API from `FrameContext.content`.\nThere is a bug in Teams mobile that returns `frameContext.content in dialog instead of `frameContext.task`. Once the bug is fixed, this change will be reverted.",
"packageName": "@microsoft/teams-js",
"email": "[email protected]",
"dependentChangeType": "patch"
}
16 changes: 15 additions & 1 deletion packages/teams-js/src/internal/dialogHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import { ApiName, ApiVersionNumber, getApiVersionTag } from './telemetry';
*/
export const dialogTelemetryVersionNumber: ApiVersionNumber = ApiVersionNumber.V_2;

const dialogSubmitWarning =
'dialog.submit should not be called from FrameContext.content.' +
'\nIf dialog.submit was called from inside the dialog, please disregard this message.' +
'\nThis issue occurs due to a bug in Teams mobile where the dialog is incorrectly identified as being in the content FrameContext.' +
'\nWe are working to resolve this.';

export function updateResizeHelper(apiVersionTag: string, dimensions: DialogSize): void {
ensureInitialized(
runtime,
Expand Down Expand Up @@ -83,11 +89,19 @@ export function botUrlOpenHelper(
}

export function urlSubmitHelper(apiVersionTag: string, result?: string | object, appIds?: string | string[]): void {
ensureInitialized(runtime, FrameContexts.task);
// FrameContext content should not be here because dialog.submit can be called only from inside of a dialog (FrameContext task)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create a TODO to track?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we know if Teams mobile has a ETA to fix it properly on their end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jekloudaMSFT do you know about the ETA? I have created a work item here:
https://office.visualstudio.com/MetaOS/_workitems/edit/10134868

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Teams mobile already has a work item for this, I'll see if I can link ours to theirs

// but it's here because Teams mobile incorrectly returns FrameContext.content when calling app.getFrameContext().
// FrameContexts.content will be removed once the bug is fixed.
ensureInitialized(runtime, FrameContexts.content, FrameContexts.task);
if (!dialog.url.isSupported()) {
throw errorNotSupportedOnPlatform;
}

// If dialog.submit is called from frameContext.content, warn the user, so they don't take dependency on this behavior
if (GlobalVars.frameContext === FrameContexts.content) {
console.warn(dialogSubmitWarning);
}

// Send tasks.completeTask instead of tasks.submitTask message for backward compatibility with Mobile clients
sendMessageToParent(apiVersionTag, 'tasks.completeTask', [
result,
Expand Down
4 changes: 2 additions & 2 deletions packages/teams-js/test/public/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('Dialog', () => {
it('should not allow calls before initialization', () => {
expect(() => dialog.url.submit()).toThrowError(errorLibraryNotInitialized);
});
const allowedContexts = [FrameContexts.task];
const allowedContexts = [FrameContexts.content, FrameContexts.task];
Object.values(FrameContexts).forEach((context) => {
if (allowedContexts.some((allowedContexts) => allowedContexts === context)) {
it(`FRAMELESS: should throw error when dialog is not supported in ${context} context`, async () => {
Expand Down Expand Up @@ -1314,7 +1314,7 @@ describe('Dialog', () => {
it('should not allow calls before initialization', () => {
expect(() => dialog.url.submit()).toThrowError(errorLibraryNotInitialized);
});
const allowedContexts = [FrameContexts.task];
const allowedContexts = [FrameContexts.content, FrameContexts.task];
Object.values(FrameContexts).forEach((context) => {
if (allowedContexts.some((allowedContexts) => allowedContexts === context)) {
it(`FRAMED: should throw error when dialog is not supported in ${context} context`, async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/teams-js/test/public/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ describe('tasks', () => {
});

describe('submitTask', () => {
const allowedContexts = [FrameContexts.task];
const allowedContexts = [FrameContexts.content, FrameContexts.task];
it('should not allow calls before initialization', () => {
expect(() => tasks.submitTask()).toThrowError(new Error(errorLibraryNotInitialized));
});
Expand Down
Loading