feat(safe-dom): add minimal SafeDOM package and runnable example#26
Merged
Conversation
Introduces tools/safe-dom/ as a standalone ReScript workspace package
implementing the SafeDOM surface the orphaned examples/SafeDOMExample.res
already assumed:
- ProvenSelector / ProvenHTML: validated-input wrappers (boundary check is
carried in the type so mount cannot fail on input shape).
- mount: proven-input mounting that returns mountResult variant.
- mountSafe / mountWhenReady: string-input helpers that validate at the
boundary and dispatch via callbacks.
- mountBatch: two-phase (validate + existence check, then mutate) for
best-effort atomic batch mounting; the trade-off (innerHTML mutations are
not transactionally reversible if the DOM races mid-batch) is documented
in-source.
Moves examples/SafeDOMExample.res into the package so the build verifies the
surface. Fixes three latent bugs in the example uncovered by the first build:
1. mountWithValidation had 6 opening braces and 5 closing - outer switch
was never closed.
2. Console.log("label", value) used JS-style varargs; switched to
RescriptCore's Console.log2 / Console.error2.
3. Template literal interpolating Array.length(...) needed ->Int.toString
(no implicit int-to-string in ReScript).
package-lock.json appears at the repo root because npm hoisted the workspace
on install - committing it locks the resolved tree across the workspace.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
tools/safe-dom/implementing the SafeDOM surface that the orphanedexamples/SafeDOMExample.resalready assumed (ProvenSelector/ProvenHTML,mount,mountSafe,mountWhenReady,mountBatch).mountWithValidationwas missing one}(outerswitchnever closed).Console.log("label", value)was JS-style; switched to RescriptCore'sConsole.log2/Console.error2.Array.length(...)needed->Int.toString(no implicit int→string in ReScript).package-lock.jsonis committed because npm hoisted the workspace on install — it locks the resolved tree across all members.Why this matters
Closes the last gap in the TS→ReScript migration: every
.ressource in the repo now builds. Previouslyexamples/SafeDOMExample.resreferencedopen SafeDOMwith no implementation anywhere — aspirational code masquerading as a runnable example.Test plan
rescript buildintools/safe-domsucceeds (no warnings).find . -name "*.ts" -not -path "*/node_modules/*" -not -path "*/.git/*"returns 0 results — antipattern check trivially passes.mountBatch(documented in-source: validation is atomic, mutation phase is best-effort and not transactionally reversible).🤖 Generated with Claude Code