Skip to content
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
2 changes: 1 addition & 1 deletion docs/pages/api-reference/liveblocks-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const client = createClient({
How to handle WebSocket messages that are larger than the maximum message size. Can be set to one of these values:
</div>

- `"default"` Don鈥檛 send anything, but log the error to the console.
- `"default"` Don鈥檛 send anything, but log the error to the console and notify useErrorListener.
- `"split"` Break the message up into chunks each of which is smaller than the maximum message size.
Beware that using `"split"` will sacrifice atomicity of changes! Depending on your use case, this may or may not be problematic.
- `"experimental-fallback-to-http"` Try sending the update over HTTP instead of WebSockets (experimental).
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api-reference/liveblocks-react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function App() {
How to handle WebSocket messages that are larger than the maximum message size. Can be set to one of these values:
</div>

- `"default"` Don鈥檛 send anything, but log the error to the console.
- `"default"` Don鈥檛 send anything, but log the error to the console and notify useErrorListener.
- `"split"` Break the message up into chunks each of which is smaller than the maximum message size.
Beware that using `"split"` will sacrifice atomicity of changes! Depending on your use case, this may or may not be problematic.
- `"experimental-fallback-to-http"` Try sending the update over HTTP instead of WebSockets (experimental).
Expand Down
12 changes: 10 additions & 2 deletions packages/liveblocks-core/src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1733,8 +1733,16 @@ export function createRoom<
// If message is too big for WebSockets, we need to follow a strategy
switch (strategy) {
case "default": {
console.error("Message is too large for websockets, not sending. Configure largeMessageStrategy option to deal with this."); // prettier-ignore
// Don't send the message
const type = "LARGE_MESSAGE_ERROR";
const err = new LiveblocksError("Message is too large for websockets", {
type,
});
const didNotify = config.errorEventSource.notify(err);
if (!didNotify) {
console.error(
"Message is too large for websockets. Configure largeMessageStrategy option or useErrorListener to handle this."
);
}
return;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/liveblocks-core/src/types/LiveblocksError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type RoomConnectionErrorContext = {
roomId: string;
};

type LargeMessageErrorContext = {
type: "LARGE_MESSAGE_ERROR";
};

// All possible errors originating from using Comments or Notifications
type CommentsOrNotificationsErrorContext =
| {
Expand Down Expand Up @@ -92,6 +96,7 @@ export type LiveblocksErrorContext = Relax<
| RoomConnectionErrorContext // from Presence, Storage, or Yjs
| CommentsOrNotificationsErrorContext // from Comments or Notifications or UserNotificationSettings
| AiConnectionErrorContext // from AI
| LargeMessageErrorContext // whena message is too large
>;

export class LiveblocksError extends Error {
Expand Down Expand Up @@ -166,6 +171,7 @@ function defaultMessageFromContext(context: LiveblocksErrorContext): string {
case "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR": return "Could not delete all inbox notifications";
case "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR": return "Could not update room subscription settings";
case "UPDATE_NOTIFICATION_SETTINGS_ERROR": return "Could not update notification settings";
case "LARGE_MESSAGE_ERROR": return "Could not send large message";

default:
return assertNever(context, "Unhandled case");
Expand Down
6 changes: 4 additions & 2 deletions packages/liveblocks-react/test-d/augmentation.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ declare global {
};

RoomEvent:
| { type: "emoji"; emoji: string }
| { type: "beep"; times?: number };
| { type: "emoji"; emoji: string }
| { type: "beep"; times?: number };

ThreadMetadata: {
color: "red" | "blue";
Expand Down Expand Up @@ -330,6 +330,7 @@ declare global {
| "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR"
| "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR"
| "UPDATE_NOTIFICATION_SETTINGS_ERROR"
| "LARGE_MESSAGE_ERROR"
>(err.context.type);
if (err.context.type === "ROOM_CONNECTION_ERROR") {
expectAssignable<number>(err.context.code);
Expand Down Expand Up @@ -373,6 +374,7 @@ declare global {
| "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR"
| "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR"
| "UPDATE_NOTIFICATION_SETTINGS_ERROR"
| "LARGE_MESSAGE_ERROR"
>(err.context.type);
if (err.context.type === "ROOM_CONNECTION_ERROR") {
expectAssignable<number>(err.context.code);
Expand Down
3 changes: 3 additions & 0 deletions packages/liveblocks-react/test-d/factories.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ ctx.useOthersListener(({ user, type }) => {
| "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR"
| "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR"
| "UPDATE_NOTIFICATION_SETTINGS_ERROR"
| "LARGE_MESSAGE_ERROR"
>(err.context.type);
if (err.context.type === "ROOM_CONNECTION_ERROR") {
expectAssignable<number>(err.context.code);
Expand Down Expand Up @@ -418,6 +419,7 @@ ctx.useOthersListener(({ user, type }) => {
| "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR"
| "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR"
| "UPDATE_NOTIFICATION_SETTINGS_ERROR"
| "LARGE_MESSAGE_ERROR"
>(err.context.type);
if (err.context.type === "ROOM_CONNECTION_ERROR") {
expectAssignable<number>(err.context.code);
Expand Down Expand Up @@ -458,6 +460,7 @@ ctx.useOthersListener(({ user, type }) => {
| "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR"
| "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR"
| "UPDATE_NOTIFICATION_SETTINGS_ERROR"
| "LARGE_MESSAGE_ERROR"
>(err.context.type);
if (err.context.type === "ROOM_CONNECTION_ERROR") {
expectAssignable<number>(err.context.code);
Expand Down
2 changes: 2 additions & 0 deletions packages/liveblocks-react/test-d/no-augmentation.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ import { expectAssignable, expectError, expectType } from "tsd";
| "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR"
| "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR"
| "UPDATE_NOTIFICATION_SETTINGS_ERROR"
| "LARGE_MESSAGE_ERROR"
>(err.context.type);
if (err.context.type === "ROOM_CONNECTION_ERROR") {
expectAssignable<number>(err.context.code);
Expand Down Expand Up @@ -275,6 +276,7 @@ import { expectAssignable, expectError, expectType } from "tsd";
| "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR"
| "UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR"
| "UPDATE_NOTIFICATION_SETTINGS_ERROR"
| "LARGE_MESSAGE_ERROR"
>(err.context.type);
if (err.context.type === "ROOM_CONNECTION_ERROR") {
expectAssignable<number>(err.context.code);
Expand Down
Loading