Skip to content

Commit 94348f0

Browse files
committed
chore(files): fix stale route TSDoc and hoist a regex literal (cleanup pass)
Post-review /cleanup: the dimensions route TSDoc still described backfill-once behavior (now overwrite-on-mismatch via the content-key CAS); the bare-pixel width regex is hoisted to module scope. No behavior change.
1 parent cd1b2be commit 94348f0

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

  • apps/sim/app
    • api/workspaces/[id]/files/[fileId]/dimensions
    • workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor

apps/sim/app/api/workspaces/[id]/files/[fileId]/dimensions/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ const logger = createLogger('WorkspaceFileDimensionsAPI')
1313
/**
1414
* PATCH /api/workspaces/[id]/files/[fileId]/dimensions
1515
*
16-
* Backfill an image file's intrinsic pixel dimensions — a pure rendering hint the editor uses to reserve
17-
* layout space before the image loads. Requires write permission and is idempotent (a no-op once the
18-
* dimensions are already stored), so the client can fire it once per image without coordination.
16+
* Store an image file's intrinsic pixel dimensions — a pure rendering hint the editor uses to reserve
17+
* layout space before the image loads. Requires write permission. The write commits whenever the row
18+
* still holds the measured storage key, overwriting any stale value so a wrong size self-corrects; the
19+
* client reports only on a real mismatch, so this is not storm-y despite not being a backfill-once no-op.
1920
*/
2021
export const PATCH = withRouteHandler(
2122
async (request: NextRequest, context: { params: Promise<{ id: string; fileId: string }> }) => {

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/image.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { useEditorEditable } from './use-editor-editable'
1010

1111
const MIN_WIDTH = 64
1212

13+
/** A bare pixel count (`"640"`) that needs a `px` suffix, vs. an already-unit'd width (`"50%"`). */
14+
const BARE_PIXEL_WIDTH = /^\d+$/
15+
1316
/**
1417
* Drag-to-resize image node view (handle at the bottom-right, revealed on selection). Dragging
1518
* commits the new pixel width to the `width` attribute, which serializes to `<img width>`.
@@ -83,7 +86,7 @@ function ResizableImageView({ node, updateAttributes, selected, editor }: ReactN
8386
}
8487

8588
const committedWidth = attrs.width
86-
? /^\d+$/.test(attrs.width)
89+
? BARE_PIXEL_WIDTH.test(attrs.width)
8790
? `${attrs.width}px`
8891
: attrs.width
8992
: undefined

0 commit comments

Comments
 (0)