Repository navigation
feat(react): adopt selective WebAPI DOM types [Codex] - #165
Draft
jderochervlk wants to merge 3 commits into
Draft
jderochervlk wants to merge 3 commits into
jderochervlk wants to merge 3 commits into
Conversation
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use WebAPI types in the React DOM bindings so elements, native events, event targets, clipboard data, touch lists, FormData, and files interoperate with WebAPI without identity casts.
Select
WebAPI.DOMTree,WebAPI.History,WebAPI.Location,WebAPI.Touch,WebAPI.DataTransfer, andWebAPI.FormData. These features compile 27 WebAPI source modules; consumers can opt into additional operation modules.Changes
WebAPI.DOMTree.elementfor roots, portals, refs, and DOM test helpers, and WebAPI history/location types in the router.currentTarget, related targets, and UI/pointerviewto options; expose pointer IDs as integers.option<WebAPI.DataTransfer.t>from clipboard data getters andWebAPI.TouchList.tfrom touch-list getters.ReactDOM.FormData.ttoWebAPI.FormData.tand files toWebAPI.DOM.file. Preserve React helper names and boxedString/Filereturn variants while sharing FormData across form actions and status values.ReactTestUtils.These are public type changes. Event targets require runtime narrowing before element-specific access; callers must handle absent
currentTarget,view, and clipboard data. Touch lists are not arrays, and React's boxed form values are distinct from WebAPI's unboxed entry values. JSX, style, and synthetic-event tag identities are unchanged.Types versus operations
Inside
@rescript/react, the WebAPI references in this change are type aliases and annotations. React's own externals remain in place: the router, DOM helpers, event getters, and FormData helpers are not rewritten to call WebAPI operations. The generated library JavaScript has no WebAPI module imports.The shared types make WebAPI operations usable directly by consumers, without casts or conversion wrappers. The examples below use actual WebAPI bindings. Many such bindings are externals that compile to direct JavaScript property/method access rather than an extra runtime wrapper.
This is not entirely a type-only change: the nullable getter annotations normalize JavaScript
nullandundefinedto ReScriptNone. Callers must handle the resulting options. React's boxed FormDataString/Filevalues are still distinct from WebAPI's unboxed entry values.Consumer examples
Consumers that name WebAPI modules should add
@rescript/webapias a direct package dependency using the same pinned snapshot as React, and select the features they use inrescript.json. For the clipboard, touch, and FormData examples:{ "dependencies": [ "@rescript/react", { "name": "@rescript/webapi", "features": ["WebAPI.DataTransfer", "WebAPI.Touch", "WebAPI.FormData"] } ] }Read clipboard text through a WebAPI binding. The React getter returns an optional DataTransfer;
getDataoperates on the same value once present. The result isoption<string>.Access an individual touch. A TouchList is not an array. WebAPI's
itembinding returns a nullable Touch, which is null when the index is absent.Use WebAPI FormData operations in a React form action. The action already receives a
ReactDOM.FormData.t, which now shares its identity withWebAPI.FormData.t. No conversion is necessary;ReactDOM.Syncmarks synchronous completion.Pass a WebAPI element directly to React. For this example, additionally select
WebAPI.DOMNodesin the consumer's WebAPI features to enable element operations.querySelectorreturns a nullable element; after converting it to an option, it can be passed straight tocreateRoot.An event's
targetis still an EventTarget, not necessarily an Element. These shared types do not justify casting arbitrary event targets to elements.Release dependency
This is a draft pending a published WebAPI version containing the selected features. The dependency currently uses immutable source snapshot
691bc3f20dc5d621d22f5bf9931b4ec086542d5f, with compiler/runtime requirements aligned to ReScript 13.0.0-alpha.7. Replace that snapshot with the corresponding published release and rerun the packed-consumer checks before landing for production.Benchmark tools and raw measurements are maintained separately on the fork's existing
feat/webapi-dom-profilebranch; none are included in this branch. The comparison below measures the exact current source revision14d7200.Build measurements
Thirty runs per configuration and build mode, with randomized configuration order within each round. Medians in milliseconds:
Against unchanged v13, this migration's medians are 47.9% higher for clean builds, 16.1% higher for cached builds, and 8.5% higher for single-file rebuilds. This is an interoperability/type-safety change, not a build-speed improvement. The migrated configuration requires v13 and was not run on v12.
The report documents source revisions, ranges, bootstrap intervals, and methodology limitations. Raw results retain all 270 samples and compiler output. OS caches, CPU affinity, and power settings were not controlled; the results describe this machine and these dependency revisions.