From 80b9d7d78807f58b00fe7a2ce60fda7287a05e20 Mon Sep 17 00:00:00 2001 From: Josh Vlk Date: Mon, 16 Nov 2026 16:09:29 -0500 Subject: [PATCH 1/5] refactor(react): own DOM props and remove JsxDOM dependency [Codex] --- .github/workflows/nodejs.yml | 1 + README.md | 17 + package.json | 1 + src/ReactDOM.res | 639 +++++++++++++++++++++++++++- src/ReactEvent.res | 13 + src/ReactEvent.res.js | 3 + src/ReactEvent.resi | 25 ++ tests/check-dom-props.py | 123 ++++++ tests/dom-props/DomPropsChecks.res | 77 ++++ tests/dom-props/ForbiddenJsxDOM.res | 2 + tests/dom-props/InvalidEvent.res | 2 + tests/dom-props/InvalidProp.res | 1 + tests/dom-props/InvalidRef.res | 1 + tests/dom-props/InvalidStyle.res | 1 + tests/dom-props/runtime.mjs | 72 ++++ 15 files changed, 972 insertions(+), 6 deletions(-) create mode 100644 tests/check-dom-props.py create mode 100644 tests/dom-props/DomPropsChecks.res create mode 100644 tests/dom-props/ForbiddenJsxDOM.res create mode 100644 tests/dom-props/InvalidEvent.res create mode 100644 tests/dom-props/InvalidProp.res create mode 100644 tests/dom-props/InvalidRef.res create mode 100644 tests/dom-props/InvalidStyle.res create mode 100644 tests/dom-props/runtime.mjs diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index fce96c3..5f46834 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -26,4 +26,5 @@ jobs: - run: npm ci - run: npm run build - run: python3 benchmarks/check-consumer.py + - run: npm run test:dom-props - run: npm run test diff --git a/README.md b/README.md index ea7d8a1..18209f6 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,23 @@ npm start See [the WebAPI profiling report](benchmarks/README.md) for the built-in DOM migration, build measurements, and local-link reproduction commands. +The intrinsic DOM props and ref types are owned by `ReactDOM`, not by the built-in +`JsxDOM` module. Use `ReactDOM.domProps`, `ReactDOM.domRef`, and the +`ReactDOM.Ref` helpers instead of explicitly annotating values with `JsxDOM` types. +Popover constructors now live here too, for example `ReactDOM.Auto` and `ReactDOM.Toggle`. +The separate `JsxDOMStyle` and `JsxEvent` aliases are not migrated yet. + +Run the DOM props regression checks with Node.js and Python 3 available: + +```sh +npm run test:dom-props +``` + +This checks the complete prop surface against the pinned compiler's definitions, +then builds a disposable consumer with the `JsxDOM` module removed from a private +runtime copy. It checks JSX and server-rendering behavior, plus rejection of +invalid props, styles, event handlers, and refs. Shared dependencies are not modified. + ### Acknowledgements This project is the next evolution of the original [reason-react](https://github.com/reasonml/reason-react) bindings. diff --git a/package.json b/package.json index f1a3d86..da991ef 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "start": "rescript watch", "clean": "rescript clean", "format": "rescript format", + "test:dom-props": "python3 tests/check-dom-props.py", "test": "echo 'tests disabled for now'" }, "keywords": [ diff --git a/src/ReactDOM.res b/src/ReactDOM.res index 3901fd2..de2493e 100644 --- a/src/ReactDOM.res +++ b/src/ReactDOM.res @@ -78,7 +78,7 @@ external domElementToObj: WebAPI.Element.t => {..} = "%identity" type style = ReactDOMStyle.t -type domRef = JsxDOM.domRef +type domRef module Ref = { type t = domRef @@ -226,7 +226,634 @@ external preinitModule: (string, preloadModuleOptions) => unit = "preinitModule" // Runtime -type domProps = JsxDOM.domProps +/** + * React's intrinsic DOM props. Based on @rescript/runtime 13.0.0-alpha.7 + * JsxDOM definitions. + * + * Copyright (C) 2015-2016 Bloomberg Finance L.P. + * Copyright (C) 2017- Hongbo Zhang, Authors of ReScript + * SPDX-License-Identifier: MIT + */ +type popover = | @as("auto") Auto | @as("manual") Manual | @as("hint") Hint + +type popoverTargetAction = | @as("toggle") Toggle | @as("show") Show | @as("hide") Hide + +type domProps = { + key?: string, + children?: Jsx.element, + ref?: domRef, + allow?: string, + @as("aria-current") + ariaCurrent?: [#page | #step | #location | #date | #time | #"true" | #"false"], + @as("aria-details") ariaDetails?: string, + @as("aria-disabled") ariaDisabled?: bool, + @as("aria-hidden") ariaHidden?: bool, + @as("aria-invalid") ariaInvalid?: [#grammar | #"false" | #spelling | #"true"], + @as("aria-keyshortcuts") ariaKeyshortcuts?: string, + @as("aria-label") ariaLabel?: string, + @as("aria-roledescription") ariaRoledescription?: string, + @as("aria-autocomplete") ariaAutocomplete?: [#inline | #list | #both | #none], + @as("aria-checked") ariaChecked?: [#"true" | #"false" | #mixed], + @as("aria-expanded") ariaExpanded?: bool, + @as("aria-haspopup") + ariaHaspopup?: [#menu | #listbox | #tree | #grid | #dialog | #"true" | #"false"], + @as("aria-level") ariaLevel?: int, + @as("aria-modal") ariaModal?: bool, + @as("aria-multiline") ariaMultiline?: bool, + @as("aria-multiselectable") ariaMultiselectable?: bool, + @as("aria-orientation") ariaOrientation?: [#horizontal | #vertical | #undefined], + @as("aria-placeholder") ariaPlaceholder?: string, + @as("aria-pressed") ariaPressed?: [#"true" | #"false" | #mixed], + @as("aria-readonly") ariaReadonly?: bool, + @as("aria-required") ariaRequired?: bool, + @as("aria-selected") ariaSelected?: bool, + @as("aria-sort") ariaSort?: string, + @as("aria-valuemax") ariaValuemax?: float, + @as("aria-valuemin") ariaValuemin?: float, + @as("aria-valuenow") ariaValuenow?: float, + @as("aria-valuetext") ariaValuetext?: string, + @as("aria-atomic") ariaAtomic?: bool, + @as("aria-busy") ariaBusy?: bool, + @as("aria-live") ariaLive?: [#off | #polite | #assertive | #rude], + @as("aria-relevant") ariaRelevant?: string, + @as("aria-dropeffect") ariaDropeffect?: [#copy | #move | #link | #execute | #popup | #none], + @as("aria-grabbed") ariaGrabbed?: bool, + @as("aria-activedescendant") ariaActivedescendant?: string, + @as("aria-colcount") ariaColcount?: int, + @as("aria-colindex") ariaColindex?: int, + @as("aria-colspan") ariaColspan?: int, + @as("aria-controls") ariaControls?: string, + @as("aria-describedby") ariaDescribedby?: string, + @as("aria-errormessage") ariaErrormessage?: string, + @as("aria-flowto") ariaFlowto?: string, + @as("aria-labelledby") ariaLabelledby?: string, + @as("aria-owns") ariaOwns?: string, + @as("aria-posinset") ariaPosinset?: int, + @as("aria-rowcount") ariaRowcount?: int, + @as("aria-rowindex") ariaRowindex?: int, + @as("aria-rowspan") ariaRowspan?: int, + @as("aria-setsize") ariaSetsize?: int, + defaultChecked?: bool, + defaultValue?: string, + accessKey?: string, + capture?: [#user | #environment], + className?: string, + contentEditable?: bool, + contextMenu?: string, + @as("data-testid") dataTestId?: string, + dir?: string, + draggable?: bool, + hidden?: bool, + id?: string, + inert?: bool, + lang?: string, + popover?: popover, + popoverTarget?: string, + popoverTargetAction?: popoverTargetAction, + role?: string, + style?: style, + spellCheck?: bool, + tabIndex?: int, + title?: string, + itemID?: string, + itemProp?: string, + itemRef?: string, + itemScope?: bool, + itemType?: string, + accept?: string, + acceptCharset?: string, + action?: string, + allowFullScreen?: bool, + alt?: string, + @as("as") as_?: string, + async?: bool, + autoComplete?: string, + autoCapitalize?: string, + autoFocus?: bool, + autoPlay?: bool, + challenge?: string, + charSet?: string, + checked?: bool, + cite?: string, + crossOrigin?: string, + cols?: int, + colSpan?: int, + content?: string, + controls?: bool, + coords?: string, + data?: string, + dateTime?: string, + default?: bool, + defer?: bool, + disabled?: bool, + download?: string, + encType?: string, + form?: string, + formAction?: string, + formTarget?: string, + formMethod?: string, + frameBorder?: int, + headers?: string, + height?: string, + high?: int, + href?: string, + hrefLang?: string, + htmlFor?: string, + httpEquiv?: string, + icon?: string, + inputMode?: string, + integrity?: string, + keyType?: string, + kind?: string, + label?: string, + list?: string, + loading?: [#lazy | #eager], + loop?: bool, + low?: int, + manifest?: string, + max?: string, + maxLength?: int, + media?: string, + mediaGroup?: string, + method?: string, + min?: string, + minLength?: int, + multiple?: bool, + muted?: bool, + name?: string, + nonce?: string, + noValidate?: bool, + @as("open") open_?: bool, + optimum?: int, + pattern?: string, + placeholder?: string, + playsInline?: bool, + poster?: string, + preload?: string, + radioGroup?: string, + readOnly?: bool, + rel?: string, + required?: bool, + reversed?: bool, + rows?: int, + rowSpan?: int, + sandbox?: string, + scope?: string, + scoped?: bool, + scrolling?: string, + selected?: bool, + shape?: string, + size?: int, + sizes?: string, + span?: int, + src?: string, + srcDoc?: string, + srcLang?: string, + srcSet?: string, + start?: int, + step?: float, + summary?: string, + target?: string, + @as("type") type_?: string, + useMap?: string, + value?: string, + width?: string, + wrap?: string, + onCancel?: ReactEvent.Synthetic.t => unit, + onCancelCapture?: ReactEvent.Synthetic.t => unit, + onClose?: ReactEvent.Synthetic.t => unit, + onCloseCapture?: ReactEvent.Synthetic.t => unit, + onFullscreenChange?: ReactEvent.Synthetic.t => unit, + onFullscreenChangeCapture?: ReactEvent.Synthetic.t => unit, + onFullscreenError?: ReactEvent.Synthetic.t => unit, + onFullscreenErrorCapture?: ReactEvent.Synthetic.t => unit, + onBeforeToggle?: ReactEvent.Toggle.t => unit, + onBeforeToggleCapture?: ReactEvent.Toggle.t => unit, + onToggle?: ReactEvent.Toggle.t => unit, + onToggleCapture?: ReactEvent.Toggle.t => unit, + onCopy?: ReactEvent.Clipboard.t => unit, + onCopyCapture?: ReactEvent.Clipboard.t => unit, + onCut?: ReactEvent.Clipboard.t => unit, + onCutCapture?: ReactEvent.Clipboard.t => unit, + onPaste?: ReactEvent.Clipboard.t => unit, + onPasteCapture?: ReactEvent.Clipboard.t => unit, + onCompositionEnd?: ReactEvent.Composition.t => unit, + onCompositionEndCapture?: ReactEvent.Composition.t => unit, + onCompositionStart?: ReactEvent.Composition.t => unit, + onCompositionStartCapture?: ReactEvent.Composition.t => unit, + onCompositionUpdate?: ReactEvent.Composition.t => unit, + onCompositionUpdateCapture?: ReactEvent.Composition.t => unit, + onKeyDown?: ReactEvent.Keyboard.t => unit, + onKeyDownCapture?: ReactEvent.Keyboard.t => unit, + onKeyPress?: ReactEvent.Keyboard.t => unit, + onKeyPressCapture?: ReactEvent.Keyboard.t => unit, + onKeyUp?: ReactEvent.Keyboard.t => unit, + onKeyUpCapture?: ReactEvent.Keyboard.t => unit, + onFocus?: ReactEvent.Focus.t => unit, + onFocusCapture?: ReactEvent.Focus.t => unit, + onBlur?: ReactEvent.Focus.t => unit, + onBlurCapture?: ReactEvent.Focus.t => unit, + onBeforeInput?: ReactEvent.Form.t => unit, + onBeforeInputCapture?: ReactEvent.Form.t => unit, + onChange?: ReactEvent.Form.t => unit, + onChangeCapture?: ReactEvent.Form.t => unit, + onInput?: ReactEvent.Form.t => unit, + onInputCapture?: ReactEvent.Form.t => unit, + onReset?: ReactEvent.Form.t => unit, + onResetCapture?: ReactEvent.Form.t => unit, + onSubmit?: ReactEvent.Form.t => unit, + onSubmitCapture?: ReactEvent.Form.t => unit, + onInvalid?: ReactEvent.Form.t => unit, + onInvalidCapture?: ReactEvent.Form.t => unit, + onAuxClick?: ReactEvent.Mouse.t => unit, + onAuxClickCapture?: ReactEvent.Mouse.t => unit, + onClick?: ReactEvent.Mouse.t => unit, + onClickCapture?: ReactEvent.Mouse.t => unit, + onContextMenu?: ReactEvent.Mouse.t => unit, + onContextMenuCapture?: ReactEvent.Mouse.t => unit, + onDoubleClick?: ReactEvent.Mouse.t => unit, + onDoubleClickCapture?: ReactEvent.Mouse.t => unit, + onDrag?: ReactEvent.Mouse.t => unit, + onDragCapture?: ReactEvent.Mouse.t => unit, + onDragEnd?: ReactEvent.Mouse.t => unit, + onDragEndCapture?: ReactEvent.Mouse.t => unit, + onDragEnter?: ReactEvent.Mouse.t => unit, + onDragEnterCapture?: ReactEvent.Mouse.t => unit, + onDragExit?: ReactEvent.Mouse.t => unit, + onDragExitCapture?: ReactEvent.Mouse.t => unit, + onDragLeave?: ReactEvent.Mouse.t => unit, + onDragLeaveCapture?: ReactEvent.Mouse.t => unit, + onDragOver?: ReactEvent.Mouse.t => unit, + onDragOverCapture?: ReactEvent.Mouse.t => unit, + onDragStart?: ReactEvent.Mouse.t => unit, + onDragStartCapture?: ReactEvent.Mouse.t => unit, + onDrop?: ReactEvent.Mouse.t => unit, + onDropCapture?: ReactEvent.Mouse.t => unit, + onMouseDown?: ReactEvent.Mouse.t => unit, + onMouseDownCapture?: ReactEvent.Mouse.t => unit, + onMouseEnter?: ReactEvent.Mouse.t => unit, + onMouseLeave?: ReactEvent.Mouse.t => unit, + onMouseMove?: ReactEvent.Mouse.t => unit, + onMouseMoveCapture?: ReactEvent.Mouse.t => unit, + onMouseOut?: ReactEvent.Mouse.t => unit, + onMouseOutCapture?: ReactEvent.Mouse.t => unit, + onMouseOver?: ReactEvent.Mouse.t => unit, + onMouseOverCapture?: ReactEvent.Mouse.t => unit, + onMouseUp?: ReactEvent.Mouse.t => unit, + onMouseUpCapture?: ReactEvent.Mouse.t => unit, + onSelect?: ReactEvent.Selection.t => unit, + onSelectCapture?: ReactEvent.Selection.t => unit, + onTouchCancel?: ReactEvent.Touch.t => unit, + onTouchCancelCapture?: ReactEvent.Touch.t => unit, + onTouchEnd?: ReactEvent.Touch.t => unit, + onTouchEndCapture?: ReactEvent.Touch.t => unit, + onTouchMove?: ReactEvent.Touch.t => unit, + onTouchMoveCapture?: ReactEvent.Touch.t => unit, + onTouchStart?: ReactEvent.Touch.t => unit, + onTouchStartCapture?: ReactEvent.Touch.t => unit, + onPointerOver?: ReactEvent.Pointer.t => unit, + onPointerOverCapture?: ReactEvent.Pointer.t => unit, + onPointerEnter?: ReactEvent.Pointer.t => unit, + onPointerDown?: ReactEvent.Pointer.t => unit, + onPointerDownCapture?: ReactEvent.Pointer.t => unit, + onPointerMove?: ReactEvent.Pointer.t => unit, + onPointerMoveCapture?: ReactEvent.Pointer.t => unit, + onPointerUp?: ReactEvent.Pointer.t => unit, + onPointerUpCapture?: ReactEvent.Pointer.t => unit, + onPointerCancel?: ReactEvent.Pointer.t => unit, + onPointerCancelCapture?: ReactEvent.Pointer.t => unit, + onPointerOut?: ReactEvent.Pointer.t => unit, + onPointerOutCapture?: ReactEvent.Pointer.t => unit, + onPointerLeave?: ReactEvent.Pointer.t => unit, + onGotPointerCapture?: ReactEvent.Pointer.t => unit, + onGotPointerCaptureCapture?: ReactEvent.Pointer.t => unit, + onLostPointerCapture?: ReactEvent.Pointer.t => unit, + onLostPointerCaptureCapture?: ReactEvent.Pointer.t => unit, + onScroll?: ReactEvent.UI.t => unit, + onScrollCapture?: ReactEvent.UI.t => unit, + onScrollEnd?: ReactEvent.UI.t => unit, + onScrollEndCapture?: ReactEvent.UI.t => unit, + onWheel?: ReactEvent.Wheel.t => unit, + onWheelCapture?: ReactEvent.Wheel.t => unit, + onAbort?: ReactEvent.Media.t => unit, + onAbortCapture?: ReactEvent.Media.t => unit, + onCanPlay?: ReactEvent.Media.t => unit, + onCanPlayCapture?: ReactEvent.Media.t => unit, + onCanPlayThrough?: ReactEvent.Media.t => unit, + onCanPlayThroughCapture?: ReactEvent.Media.t => unit, + onDurationChange?: ReactEvent.Media.t => unit, + onDurationChangeCapture?: ReactEvent.Media.t => unit, + onEmptied?: ReactEvent.Media.t => unit, + onEmptiedCapture?: ReactEvent.Media.t => unit, + onEncrypted?: ReactEvent.Media.t => unit, + onEncryptedCapture?: ReactEvent.Media.t => unit, + onEnded?: ReactEvent.Media.t => unit, + onEndedCapture?: ReactEvent.Media.t => unit, + onError?: ReactEvent.Media.t => unit, + onErrorCapture?: ReactEvent.Media.t => unit, + onLoadedData?: ReactEvent.Media.t => unit, + onLoadedDataCapture?: ReactEvent.Media.t => unit, + onLoadedMetadata?: ReactEvent.Media.t => unit, + onLoadedMetadataCapture?: ReactEvent.Media.t => unit, + onLoadStart?: ReactEvent.Media.t => unit, + onLoadStartCapture?: ReactEvent.Media.t => unit, + onPause?: ReactEvent.Media.t => unit, + onPauseCapture?: ReactEvent.Media.t => unit, + onPlay?: ReactEvent.Media.t => unit, + onPlayCapture?: ReactEvent.Media.t => unit, + onPlaying?: ReactEvent.Media.t => unit, + onPlayingCapture?: ReactEvent.Media.t => unit, + onProgress?: ReactEvent.Media.t => unit, + onProgressCapture?: ReactEvent.Media.t => unit, + onRateChange?: ReactEvent.Media.t => unit, + onRateChangeCapture?: ReactEvent.Media.t => unit, + onResize?: ReactEvent.Media.t => unit, + onResizeCapture?: ReactEvent.Media.t => unit, + onSeeked?: ReactEvent.Media.t => unit, + onSeekedCapture?: ReactEvent.Media.t => unit, + onSeeking?: ReactEvent.Media.t => unit, + onSeekingCapture?: ReactEvent.Media.t => unit, + onStalled?: ReactEvent.Media.t => unit, + onStalledCapture?: ReactEvent.Media.t => unit, + onSuspend?: ReactEvent.Media.t => unit, + onSuspendCapture?: ReactEvent.Media.t => unit, + onTimeUpdate?: ReactEvent.Media.t => unit, + onTimeUpdateCapture?: ReactEvent.Media.t => unit, + onVolumeChange?: ReactEvent.Media.t => unit, + onVolumeChangeCapture?: ReactEvent.Media.t => unit, + onWaiting?: ReactEvent.Media.t => unit, + onWaitingCapture?: ReactEvent.Media.t => unit, + onLoad?: ReactEvent.Image.t => unit, + onLoadCapture?: ReactEvent.Image.t => unit, + onAnimationStart?: ReactEvent.Animation.t => unit, + onAnimationStartCapture?: ReactEvent.Animation.t => unit, + onAnimationEnd?: ReactEvent.Animation.t => unit, + onAnimationEndCapture?: ReactEvent.Animation.t => unit, + onAnimationIteration?: ReactEvent.Animation.t => unit, + onAnimationIterationCapture?: ReactEvent.Animation.t => unit, + onTransitionCancel?: ReactEvent.Transition.t => unit, + onTransitionCancelCapture?: ReactEvent.Transition.t => unit, + onTransitionRun?: ReactEvent.Transition.t => unit, + onTransitionRunCapture?: ReactEvent.Transition.t => unit, + onTransitionStart?: ReactEvent.Transition.t => unit, + onTransitionStartCapture?: ReactEvent.Transition.t => unit, + onTransitionEnd?: ReactEvent.Transition.t => unit, + onTransitionEndCapture?: ReactEvent.Transition.t => unit, + accentHeight?: string, + accumulate?: string, + additive?: string, + alignmentBaseline?: string, + allowReorder?: string, + alphabetic?: string, + amplitude?: string, + arabicForm?: string, + ascent?: string, + attributeName?: string, + attributeType?: string, + autoReverse?: string, + azimuth?: string, + baseFrequency?: string, + baseProfile?: string, + baselineShift?: string, + bbox?: string, + begin?: string, + bias?: string, + by?: string, + calcMode?: string, + capHeight?: string, + clip?: string, + clipPath?: string, + clipPathUnits?: string, + clipRule?: string, + colorInterpolation?: string, + colorInterpolationFilters?: string, + colorProfile?: string, + colorRendering?: string, + contentScriptType?: string, + contentStyleType?: string, + cursor?: string, + cx?: string, + cy?: string, + d?: string, + decelerate?: string, + descent?: string, + diffuseConstant?: string, + direction?: string, + display?: string, + divisor?: string, + dominantBaseline?: string, + dur?: string, + dx?: string, + dy?: string, + edgeMode?: string, + elevation?: string, + enableBackground?: string, + end?: string, + exponent?: string, + externalResourcesRequired?: string, + fill?: string, + fillOpacity?: string, + fillRule?: string, + filter?: string, + filterRes?: string, + filterUnits?: string, + floodColor?: string, + floodOpacity?: string, + focusable?: string, + fontFamily?: string, + fontSize?: string, + fontSizeAdjust?: string, + fontStretch?: string, + fontStyle?: string, + fontVariant?: string, + fontWeight?: string, + fomat?: string, + from?: string, + fx?: string, + fy?: string, + g1?: string, + g2?: string, + glyphName?: string, + glyphOrientationHorizontal?: string, + glyphOrientationVertical?: string, + glyphRef?: string, + gradientTransform?: string, + gradientUnits?: string, + hanging?: string, + horizAdvX?: string, + horizOriginX?: string, + ideographic?: string, + imageRendering?: string, + @as("in") in_?: string, + in2?: string, + intercept?: string, + k?: string, + k1?: string, + k2?: string, + k3?: string, + k4?: string, + kernelMatrix?: string, + kernelUnitLength?: string, + kerning?: string, + keyPoints?: string, + keySplines?: string, + keyTimes?: string, + lengthAdjust?: string, + letterSpacing?: string, + lightingColor?: string, + limitingConeAngle?: string, + local?: string, + markerEnd?: string, + markerHeight?: string, + markerMid?: string, + markerStart?: string, + markerUnits?: string, + markerWidth?: string, + mask?: string, + maskContentUnits?: string, + maskUnits?: string, + mathematical?: string, + mode?: string, + numOctaves?: string, + offset?: string, + opacity?: string, + operator?: string, + order?: string, + orient?: string, + orientation?: string, + origin?: string, + overflow?: string, + overflowX?: string, + overflowY?: string, + overlinePosition?: string, + overlineThickness?: string, + paintOrder?: string, + panose1?: string, + pathLength?: string, + patternContentUnits?: string, + patternTransform?: string, + patternUnits?: string, + pointerEvents?: string, + points?: string, + pointsAtX?: string, + pointsAtY?: string, + pointsAtZ?: string, + preserveAlpha?: string, + preserveAspectRatio?: string, + primitiveUnits?: string, + r?: string, + radius?: string, + referrerPolicy?: string, + refX?: string, + refY?: string, + renderingIntent?: string, + repeatCount?: string, + repeatDur?: string, + requiredExtensions?: string, + requiredFeatures?: string, + restart?: string, + result?: string, + rotate?: string, + rx?: string, + ry?: string, + scale?: string, + seed?: string, + shapeRendering?: string, + slope?: string, + slot?: string, + spacing?: string, + specularConstant?: string, + specularExponent?: string, + speed?: string, + spreadMethod?: string, + startOffset?: string, + stdDeviation?: string, + stemh?: string, + stemv?: string, + stitchTiles?: string, + stopColor?: string, + stopOpacity?: string, + strikethroughPosition?: string, + strikethroughThickness?: string, + string?: string, + stroke?: string, + strokeDasharray?: string, + strokeDashoffset?: string, + strokeLinecap?: string, + strokeLinejoin?: string, + strokeMiterlimit?: string, + strokeOpacity?: string, + strokeWidth?: string, + surfaceScale?: string, + systemLanguage?: string, + tableValues?: string, + targetX?: string, + targetY?: string, + textAnchor?: string, + textDecoration?: string, + textLength?: string, + textRendering?: string, + to?: string, + transform?: string, + u1?: string, + u2?: string, + underlinePosition?: string, + underlineThickness?: string, + unicode?: string, + unicodeBidi?: string, + unicodeRange?: string, + unitsPerEm?: string, + vAlphabetic?: string, + vHanging?: string, + vIdeographic?: string, + vMathematical?: string, + values?: string, + vectorEffect?: string, + version?: string, + vertAdvX?: string, + vertAdvY?: string, + vertOriginX?: string, + vertOriginY?: string, + viewBox?: string, + viewTarget?: string, + visibility?: string, + widths?: string, + wordSpacing?: string, + writingMode?: string, + x?: string, + x1?: string, + x2?: string, + xChannelSelector?: string, + xHeight?: string, + xlinkActuate?: string, + xlinkArcrole?: string, + xlinkHref?: string, + xlinkRole?: string, + xlinkShow?: string, + xlinkTitle?: string, + xlinkType?: string, + xmlns?: string, + xmlnsXlink?: string, + xmlBase?: string, + xmlLang?: string, + xmlSpace?: string, + y?: string, + y1?: string, + y2?: string, + yChannelSelector?: string, + z?: string, + zoomAndPan?: string, + about?: string, + datatype?: string, + inlist?: string, + prefix?: string, + property?: string, + resource?: string, + typeof?: string, + vocab?: string, + dangerouslySetInnerHTML?: {"__html": string}, + suppressContentEditableWarning?: bool, +} @variadic @module("react") external createElement: (string, ~props: domProps=?, array) => React.element = @@ -242,15 +869,15 @@ external createDOMElementVariadic: ( external someElement: React.element => option = "%identity" @module("react/jsx-runtime") -external jsx: (string, JsxDOM.domProps) => Jsx.element = "jsx" +external jsx: (string, domProps) => Jsx.element = "jsx" @module("react/jsx-runtime") -external jsxKeyed: (string, JsxDOM.domProps, ~key: string=?, @ignore unit) => Jsx.element = "jsx" +external jsxKeyed: (string, domProps, ~key: string=?, @ignore unit) => Jsx.element = "jsx" @module("react/jsx-runtime") -external jsxs: (string, JsxDOM.domProps) => Jsx.element = "jsxs" +external jsxs: (string, domProps) => Jsx.element = "jsxs" @module("react/jsx-runtime") -external jsxsKeyed: (string, JsxDOM.domProps, ~key: string=?, @ignore unit) => Jsx.element = "jsxs" +external jsxsKeyed: (string, domProps, ~key: string=?, @ignore unit) => Jsx.element = "jsxs" module Style = ReactDOMStyle diff --git a/src/ReactEvent.res b/src/ReactEvent.res index 6f46f61..c5a7237 100644 --- a/src/ReactEvent.res +++ b/src/ReactEvent.res @@ -270,3 +270,16 @@ module Transition = { @get external pseudoElement: t => string = "pseudoElement" @get external elapsedTime: t => float = "elapsedTime" } + +module Toggle = { + type tag = JsxEvent.Toggle.tag + type t = synthetic + + include MakeEventWithType({type t = t}) + + @get external oldState: t => [#closed | #"open"] = "oldState" + @get external newState: t => [#closed | #"open"] = "newState" + + /** The element that triggered the toggle. Available in React 19.3 and later. */ + @get @return(nullable) external source: t => option = "source" +} diff --git a/src/ReactEvent.res.js b/src/ReactEvent.res.js index 5303ddd..ac17a6e 100644 --- a/src/ReactEvent.res.js +++ b/src/ReactEvent.res.js @@ -33,6 +33,8 @@ let Animation = {}; let Transition = {}; +let Toggle = {}; + export { Synthetic, Clipboard, @@ -50,5 +52,6 @@ export { Image, Animation, Transition, + Toggle, } /* No side effect */ diff --git a/src/ReactEvent.resi b/src/ReactEvent.resi index a59c973..4b68cb5 100644 --- a/src/ReactEvent.resi +++ b/src/ReactEvent.resi @@ -493,3 +493,28 @@ module Transition: { @get external pseudoElement: t => string = "pseudoElement" @get external elapsedTime: t => float = "elapsedTime" } + +module Toggle: { + type tag = JsxEvent.Toggle.tag + type t = synthetic + @get external bubbles: t => bool = "bubbles" + @get external cancelable: t => bool = "cancelable" + @get external currentTarget: t => {..} = "currentTarget" + @get external defaultPrevented: t => bool = "defaultPrevented" + @get external eventPhase: t => int = "eventPhase" + @get external isTrusted: t => bool = "isTrusted" + @get external nativeEvent: t => {..} = "nativeEvent" + @send external preventDefault: t => unit = "preventDefault" + @send external isDefaultPrevented: t => bool = "isDefaultPrevented" + @send external stopPropagation: t => unit = "stopPropagation" + @send external isPropagationStopped: t => bool = "isPropagationStopped" + @get external target: t => {..} = "target" + @get external timeStamp: t => float = "timeStamp" + @get external type_: t => string = "type" + @send external persist: t => unit = "persist" + @get external oldState: t => [#closed | #"open"] = "oldState" + @get external newState: t => [#closed | #"open"] = "newState" + + /** The element that triggered the toggle. Available in React 19.3 and later. */ + @get @return(nullable) external source: t => option = "source" +} diff --git a/tests/check-dom-props.py b/tests/check-dom-props.py new file mode 100644 index 0000000..fcedc81 --- /dev/null +++ b/tests/check-dom-props.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +"""Compile and run a real React consumer with the built-in JsxDOM unavailable.""" + +import json +from pathlib import Path +import re +import shutil +import subprocess +import tempfile + + +ROOT = Path(__file__).resolve().parents[1] +CASES = ROOT / "tests" / "dom-props" + + +def copy_sources(source, destination): + destination.mkdir(parents=True) + for name in ("package.json", "rescript.json"): + shutil.copy(source / name, destination / name) + for path in (source / "src").rglob("*"): + if path.suffix in (".res", ".resi"): + target = destination / path.relative_to(source) + target.parent.mkdir(parents=True, exist_ok=True) + shutil.copy(path, target) + + +def prepare(fixture): + packages = fixture / "node_modules" + packages.mkdir() + scoped = packages / "@rescript" + scoped.mkdir() + copy_sources(ROOT, scoped / "react") + copy_sources((ROOT / "node_modules/@rescript/webapi").resolve(), scoped / "webapi") + shutil.copytree( + ROOT / "node_modules/@rescript/runtime", scoped / "runtime", + ignore=shutil.ignore_patterns("JsxDOM.*"), + ) + # The CLI resolves its runtime relative to itself, so it must not be a symlink + # back to the shared compiler package and its intact runtime. + shutil.copytree(ROOT / "node_modules/rescript", packages / "rescript") + for name in ("react", "react-dom"): + (packages / name).symlink_to((ROOT / "node_modules" / name).resolve(), target_is_directory=True) + config = { + "name": "react-dom-props-check", + "sources": ["src"], + "jsx": {"version": 4}, + "dependencies": [ + "@rescript/react", + json.loads((ROOT / "rescript.json").read_text())["dependencies"][0], + ], + "package-specs": {"module": "esmodule", "in-source": True}, + "suffix": ".res.js", + } + (fixture / "rescript.json").write_text(json.dumps(config, indent=2) + "\n") + (fixture / "package.json").write_text('{"name":"react-dom-props-check","private":true,"type":"module"}\n') + (fixture / "src").mkdir() + shutil.copy(CASES / "DomPropsChecks.res", fixture / "src") + + +def build(fixture): + compiler = fixture / "node_modules/rescript/cli/rescript.js" + result = subprocess.run(["node", str(compiler), "build"], cwd=fixture, capture_output=True, text=True) + return result.returncode, result.stdout + result.stderr + + +def require_build(fixture): + code, log = build(fixture) + if code: + raise RuntimeError(f"Consumer compilation failed:\n{log}") + + +def verify_rejection(fixture, name, expected): + target = fixture / "src" / name + shutil.copy(CASES / name, target) + try: + code, log = build(fixture) + if code == 0 or not all(text in log for text in expected): + raise RuntimeError(f"Expected {name} rejection matching {expected}:\n{log}") + print(f"PASS: expected rejection of {name}") + finally: + target.unlink() + require_build(fixture) + + +def normalize_record(source): + match = re.search(r"^type domProps = \{\n(.*?)^\}", source, flags=re.M | re.S) + if not match: + raise RuntimeError("Could not find the concrete domProps record") + without_comments = re.sub(r"/\*.*?\*/|//[^\n]*", "", match[1], flags=re.S) + return re.sub(r"\s+", "", without_comments) + + +def verify_prop_surface(): + original = (ROOT / "node_modules/@rescript/runtime/lib/ocaml/JsxDOM.res").read_text() + expected = original.replace("JsxEvent.", "ReactEvent.").replace("Jsx.element", "React.element") + actual = (ROOT / "src/ReactDOM.res").read_text().replace("Jsx.element", "React.element") + if normalize_record(actual) != normalize_record(expected): + raise RuntimeError("Local prop fields differ from the pinned runtime beyond ownership changes") + if re.search(r"\bJsxDOM\b", re.sub(r"/\*.*?\*/|//[^\n]*", "", actual, flags=re.S)): + raise RuntimeError("ReactDOM still references the built-in JsxDOM module") + print("PASS: full pinned prop surface preserved with local type ownership") + + +def main(): + verify_prop_surface() + with tempfile.TemporaryDirectory(prefix=".dom-props-", dir=ROOT / "node_modules") as directory: + fixture = Path(directory) + prepare(fixture) + require_build(fixture) + print("PASS: consumer and React sources compile without the JsxDOM interface") + for name, expected in ( + ("ForbiddenJsxDOM.res", ("JsxDOM", "can't be found")), + ("InvalidProp.res", ("definitelyNotAProp", "field")), + ("InvalidStyle.res", ("int", "string")), + ("InvalidEvent.res", ("Keyboard", "Mouse")), + ("InvalidRef.res", ("int", "domRef")), + ): + verify_rejection(fixture, name, expected) + subprocess.run(["node", str(CASES / "runtime.mjs"), str(fixture)], cwd=ROOT, check=True) + + +if __name__ == "__main__": + main() diff --git a/tests/dom-props/DomPropsChecks.res b/tests/dom-props/DomPropsChecks.res new file mode 100644 index 0000000..41eb5ff --- /dev/null +++ b/tests/dom-props/DomPropsChecks.res @@ -0,0 +1,77 @@ +let empty =
+let single =
{React.string("child")}
+ +let multiple = +
+ + +
+ +let keyed =
{React.string("child")}
+ +let keyedMultiple = +
+ + +
+ +let optionalKey = key =>
+ +let baseProps: ReactDOM.domProps = {id: "base", title: "kept"} +let spreadOnly =
+let spreadOverride =
+ +let styles: ReactDOMStyle.t = {color: "red", marginTop: "2px"} + +let styled = +
+ +let customStyle =
+ +let svg = + + + + +let rawHtml =
raw"}} /> +let popover =