Skip to content
Closed
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
12 changes: 12 additions & 0 deletions packages/editor/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { HistoryEntry } from '@tldraw/store';
import { IndexKey } from '@tldraw/utils';
import { JsonObject } from '@tldraw/utils';
import { JSX } from 'react/jsx-runtime';
import { JSXElementConstructor } from 'react';
import { LegacyMigrations } from '@tldraw/store';
import { MigrationSequence } from '@tldraw/store';
import { NamedExoticComponent } from 'react';
Expand Down Expand Up @@ -657,6 +658,9 @@ export const DefaultShapeIndicator: NamedExoticComponent<TLShapeIndicatorProps>;
// @public (undocumented)
export const DefaultShapeIndicators: NamedExoticComponent<TLShapeIndicatorsProps>;

// @public (undocumented)
export function DefaultShapeRenderer({ renderShape }: TLShapeRendererProps): ReactElement<unknown, JSXElementConstructor<any> | string>[];

// @public (undocumented)
export const DefaultShapeWrapper: ForwardRefExoticComponent<TLShapeWrapperProps & RefAttributes<HTMLDivElement>>;

Expand Down Expand Up @@ -3574,6 +3578,8 @@ export interface TLEditorComponents {
// (undocumented)
ShapeIndicators?: ComponentType | null;
// (undocumented)
ShapeRenderer?: ComponentType<TLShapeRendererProps> | null;
// (undocumented)
ShapeWrapper?: ComponentType<TLShapeWrapperProps & RefAttributes<HTMLDivElement>> | null;
// (undocumented)
SnapIndicator?: ComponentType<TLSnapIndicatorProps> | null;
Expand Down Expand Up @@ -4290,6 +4296,12 @@ export interface TLShapeIndicatorsProps {
showAll?: boolean;
}

// @public (undocumented)
export interface TLShapeRendererProps {
// (undocumented)
renderShape(shape: TLRenderingShape): ReactElement;
}

// @public
export interface TLShapeUtilCanBeLaidOutOpts {
shapes?: TLShape[];
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export { DefaultBackground } from './lib/components/default-components/DefaultBa
export { DefaultBrush, type TLBrushProps } from './lib/components/default-components/DefaultBrush'
export {
DefaultCanvas,
DefaultShapeRenderer,
type TLCanvasComponentProps,
type TLShapeRendererProps,
} from './lib/components/default-components/DefaultCanvas'
export {
DefaultCollaboratorHint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useQuickReactor, useValue } from '@tldraw/state-react'
import { TLHandle, TLShapeId } from '@tldraw/tlschema'
import { dedupe, modulate, objectMapValues } from '@tldraw/utils'
import classNames from 'classnames'
import { Fragment, JSX, useEffect, useRef, useState } from 'react'
import { Fragment, JSX, ReactElement, useEffect, useRef, useState } from 'react'
import { tlenv } from '../../globals/environment'
import { useCanvasEvents } from '../../hooks/useCanvasEvents'
import { useCoarsePointer } from '../../hooks/useCoarsePointer'
Expand All @@ -26,6 +26,7 @@ import { GeometryDebuggingView } from '../GeometryDebuggingView'
import { LiveCollaborators } from '../LiveCollaborators'
import { MenuClickCapture } from '../MenuClickCapture'
import { Shape } from '../Shape'
import type { TLRenderingShape } from '../../editor/Editor'

/** @public */
export interface TLCanvasComponentProps {
Expand Down Expand Up @@ -433,22 +434,31 @@ function ReflowIfNeeded() {
}

function ShapesToDisplay() {
const editor = useEditor()

const renderingShapes = useValue('rendering shapes', () => editor.getVisibleRenderingShapes(), [
editor,
])
const { ShapeRenderer } = useEditorComponents()
const Renderer = ShapeRenderer ?? DefaultShapeRenderer
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Null ShapeRenderer silently falls back instead of disabling

Medium Severity

The ShapeRenderer type includes | null, following the convention of other editor components where null means "disable this component." However, the consumption site uses ShapeRenderer ?? DefaultShapeRenderer, which silently falls back to the default when null is provided. Every other nullable component in the codebase uses if (!Component) return null or {Component && ...} to respect the null-means-disabled contract. This breaks the established API contract — a user passing ShapeRenderer: null would expect shape rendering to be disabled but would instead get the default renderer.

Additional Locations (1)

Fix in Cursor Fix in Web


return (
<>
{renderingShapes.map((result) => (
<Shape key={result.id + '_shape'} {...result} />
))}
<Renderer renderShape={(shape) => <Shape key={shape.id + '_shape'} {...shape} />} />
{tlenv.isSafari && <ReflowIfNeeded />}
</>
)
}

/** @public */
export interface TLShapeRendererProps {
renderShape(shape: TLRenderingShape): ReactElement
}

/** @public @react */
export function DefaultShapeRenderer({ renderShape }: TLShapeRendererProps) {
const editor = useEditor()
const renderingShapes = useValue('rendering shapes', () => editor.getVisibleRenderingShapes(), [
editor,
])
return renderingShapes.map((shape) => renderShape(shape))
}

function HintedShapeIndicator() {
const editor = useEditor()
const { ShapeIndicator } = useEditorComponents()
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/lib/hooks/useEditorComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { DefaultBrush, TLBrushProps } from '../components/default-components/Def
import {
DefaultCanvas,
TLCanvasComponentProps,
DefaultShapeRenderer,
TLShapeRendererProps,
} from '../components/default-components/DefaultCanvas'
import {
DefaultCollaboratorHint,
Expand Down Expand Up @@ -72,6 +74,7 @@ export interface TLEditorComponents {
SelectionForeground?: ComponentType<TLSelectionForegroundProps> | null
ShapeIndicator?: ComponentType<TLShapeIndicatorProps> | null
ShapeIndicators?: ComponentType | null
ShapeRenderer?: ComponentType<TLShapeRendererProps> | null
ShapeWrapper?: ComponentType<TLShapeWrapperProps & RefAttributes<HTMLDivElement>> | null
SnapIndicator?: ComponentType<TLSnapIndicatorProps> | null
Spinner?: ComponentType<React.SVGProps<SVGSVGElement>> | null
Expand Down Expand Up @@ -119,6 +122,7 @@ export function EditorComponentsProvider({
SelectionForeground: DefaultSelectionForeground,
ShapeIndicator: DefaultShapeIndicator,
ShapeIndicators: DefaultShapeIndicators,
ShapeRenderer: DefaultShapeRenderer,
ShapeWrapper: DefaultShapeWrapper,
SnapIndicator: DefaultSnapIndicator,
Spinner: DefaultSpinner,
Expand Down
Loading