Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: add websocket close handling#17548

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jaaydenh merged 3 commits intomainfromjaaydenh/dynamic-params-websocket-close
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
6 changes: 6 additions & 0 deletionssite/src/api/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1015,9 +1015,11 @@ class ApiMethods {
{
onMessage,
onError,
onClose,
}: {
onMessage: (response: TypesGen.DynamicParametersResponse) => void;
onError: (error: Error) => void;
onClose: () => void;
},
): WebSocket => {
const socket = createWebSocket(
Expand All@@ -1033,6 +1035,10 @@ class ApiMethods {
socket.close();
});

socket.addEventListener("close", () => {
onClose();
});

return socket;
};

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
importtype {ApiErrorResponse } from "api/errors";
import{ typeApiErrorResponse, DetailedError } from "api/errors";
import { checkAuthorization } from "api/queries/authCheck";
import {
templateByName,
Expand DownExpand Up@@ -107,6 +107,15 @@ const CreateWorkspacePageExperimental: FC = () => {
onError: (error) => {
setWsError(error);
},
onClose: () => {
// There is no reason for the websocket to close while a user is on the page
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The assumption is that if the websocket closes while the component is mounted, that this is unexpected and we should inform the user with an error in the UI

setWsError(
new DetailedError(
"Websocket connection for dynamic parameters unexpectedly closed.",
"Refresh the page to reset the form.",
),
);
},
},
);

Expand DownExpand Up@@ -141,7 +150,7 @@ const CreateWorkspacePageExperimental: FC = () => {
} = useExternalAuth(realizedVersionId);

const isLoadingFormData =
ws.current?.readyState!== WebSocket.OPEN ||
ws.current?.readyState=== WebSocket.CONNECTING ||
templateQuery.isLoading ||
permissionsQuery.isLoading;
const loadFormDataError = templateQuery.error ?? permissionsQuery.error;
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
import type { Meta, StoryObj } from "@storybook/react";
import { DetailedError } from "api/errors";
import { chromatic } from "testHelpers/chromatic";
import { MockTemplate, MockUser } from "testHelpers/entities";
import { CreateWorkspacePageViewExperimental } from "./CreateWorkspacePageViewExperimental";

const meta: Meta<typeof CreateWorkspacePageViewExperimental> = {
title: "Pages/CreateWorkspacePageViewExperimental",
parameters: { chromatic },
component: CreateWorkspacePageViewExperimental,
args: {
autofillParameters: [],
diagnostics: [],
defaultName: "",
defaultOwner: MockUser,
externalAuth: [],
externalAuthPollingState: "idle",
hasAllRequiredExternalAuth: true,
mode: "form",
parameters: [],
permissions: {
createWorkspaceForAny: true,
},
presets: [],
sendMessage: () => {},
template: MockTemplate,
},
};

export default meta;
type Story = StoryObj<typeof CreateWorkspacePageViewExperimental>;

export const WebsocketError: Story = {
args: {
error: new DetailedError(
"Websocket connection for dynamic parameters unexpectedly closed.",
"Refresh the page to reset the form.",
),
},
};
Loading

[8]ページ先頭

©2009-2025 Movatter.jp