Skip to content

feat(mobile): render Mermaid diagrams on the page from one deferred engine artifact (OTA phase C, C7.10 B) - #21871

Merged
Jinwoo-H merged 17 commits into
mainfrom
ota-c7-10b-mermaid
Sep 21, 2026
Merged

Jinwoo-H merged 17 commits into
mainfrom
ota-c7-10b-mermaid

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​839 $\color{#cf222e}{\Huge{\mathbf{−}}}$​117 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​722
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​351 $\color{#cf222e}{\Huge{\mathbf{−}}}$​46 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​305

Summary

Phase C, C7.10 PR B (ruling 26: the OTA page loses no capability; ruling 28: the download fence is the static closure): Mermaid diagrams render on the page. MermaidDiagram.web.tsx showed the diagram's source in a box; it now renders the diagram from the same mermaid package the native document embeds, with the same configuration (securityLevel: 'strict', theme: 'dark', the five themeVariables from mobile-theme, base-driven sizing, the native component's failure fallback for a diagram that throws), shared through mermaid-diagram-config.ts so the two hosts read one object. Inert: no route serves a PR sidebar until C7.7; released RPCs unchanged. The native screen's behaviour is the same except for one improvement that the shared config carries: suppressErrorRendering: true, so a diagram that fails still falls back to source exactly as before and no longer flashes Mermaid's own error diagram behind the fallback (pinned on both engines: without the flag the case reads 1 SVG against 0).

The engine is one deferred artifact, not the package's lazy chunks. import('mermaid') in a page bundle emits 103 diagram-type chunks (bundle scripts 69 → 172, manifest assets 112 → 215 against the shell's 256), and every chunk ships in the generation download regardless, so the split buys no transfer and costs the asset budget: the derived ceiling would have crossed 256 at 24 routes instead of 50. build-mermaid-page-engine.mjs (postinstall, beside the native engine's generator) bundles mermaid once with splitting: false into mermaid-page-engine.generated.ts (gitignored, lint-ignored), and mermaid-page-engine.ts loads it by one dynamic import with a typed return that names the two calls the component makes; no cast. Scripts and assets each cost exactly one more than a bundle with no deferred engine (69/112 vs 68/111).

measure main head
session route module list 4,320 4,323
mermaid in the route's static closure 0 0
chunks fetched for one graph TD — 1
bytes read from the generation for it — 3,482,965
first render, median of 5, WebKit / Chromium — 110 ms / 139 ms (chunked would be 97 / 64: +13 ms and +75 ms, once per session)

Rendered output equals the native document's: 17,143 bytes on the page versus 17,504 from the native buildHtml path, byte-equal at 15,447 once the diagram id and the xmlns:xlink the native innerHTML serialisation adds are normalised; same viewBox, same tag counts, same 59 injected style rules.

Under the shipped CSP (config/scripts/mobile-web-app-mermaid-render.test.mjs, Chromium and WebKit): zero violations rendering a diagram, zero eval / new Function (both patched before the import so an internal JIT probe is counted), zero page errors; a hostile diagram (<script> in a label, </script>, an onerror attribute, a javascript: click) renders with 0 <script> elements, 0 on* attributes, 0 javascript: hrefs and window.__pwned null; a broken diagram falls back to source (control); a source change leaves one SVG. Mermaid injects two <style> elements, which style-src 'self' 'unsafe-inline' already carries.

The generation budget (verify-mobile-web-app-bundle.mjs, 9 MiB ceiling): the built bundle goes 4,539,090 → 8,016,714 bytes across 112 assets, 84.9%, leaving 1,420,470 bytes for C7.10 C/D and C7.7. Deferring the engine defers its evaluation and its read, never the download; the engine ships in every generation, as the 3.7 MB engine string ships in every native build. Recorded on C7.8's budget row. The script-count fence is at break-even at 14 routes (69 against a 4r + 16 bound of 72; the spread measured 4–9 scripts per route, method stated in the comment), so the next route that shares less than its neighbours breaches it; a new assertion states the slope from the function.

Round 1 (fresh) found no blocker; folds: the native document's inline <script> now takes the shared config through the same escaping as the source (red-first: a config carrying </script><script> put four raw closers where a benign build has two); the page loader is pinned (engine: Mermaid) => PageMermaid so an absurd render signature reds tsc (before, both members inferred as any); the four-point script series re-measured with the method stated (8→32, 10→43, 12→61, 14→69).

Fences. mobile-web-app-session-terminal-closure.test.mjs reads the download on entryStaticClosure (import-statement edges only): the engine is absent from every chunk the route reaches statically and present once in the deferred half (lead control: a static import of the artifact reds it). The asset-budget test keeps a control that a lazily-chunked engine (103 extra scripts) breaches the ceiling. Every source census that reads file text under mobile/src (nine: the type-only params boundary, unvalidated request port, operation cast fence, subscription boundary, unchecked reader boundary, lifecycle owner, reanimated web mapper deps, timer receiver, web-shell flag) now walks through one census-source-files.ts, which skips every *.generated.ts listed in mobile/.gitignore. The tenth walker, mobile-web-app-web-overrides.test.mjs, matches .web.* by name and never reads a file, so it neither pays the parse nor can be fooled by an artifact. Controls: a planted *.generated.ts carrying exactly the import a census hunts is not returned while an ordinary sibling with the same text is; the walker's exclusion is held to every artifact named in mobile/.gitignore, so a sixth artifact under an unmatched name reds; and a census that walks on its own spelling reds. This is what the CI timeout in the type-only params census was: the vendored mermaid engines are 7.2 MB of the tree's 7.9 MB of generated TypeScript, and parsing them tipped a case from 831 ms (main, four artifacts) to 1,358 ms with this artifact against a 5 s timeout on a loaded shard. With the exclusion the case measures 788 ms with the artifact present (lead reproduction: three runs at 818–831 ms tests total for the file, artifact present).

Commits:

commit what
b7c36e65e9 test(mobile): measure mermaid rendered in the page
c9b7c3b4b0 test(mobile): fence the session download rather than its module list
576db105a2 feat(mobile): render mermaid in the page
4b471c5b4c merge of origin/main (no footer)
ab51375f49 fix(mobile): budget the deferred engine's chunks apart from the routes (superseded)
bd07d7108d refactor(mobile): pre-bundle the page's mermaid into one artifact
e3bc91a5f2 revert(mobile): drop the deferred-engine ceiling term, keep the control
c0c7f806ff merge of origin/main (30f2bc60f9)
26536f7066 test(mobile): keep build output out of the raw-request-port census
0d8f1c4fb2 fix(mobile): escape the shared config into the native document's inline script (round 1)
81a94a5726 test(mobile): pin the page engine's signatures against the package's types (round 1)
c475bcbdea test(mobile): re-measure the chunk series and record the generation byte total (round 1)
35d7e11bbd test(mobile): pin the native fallback under suppressErrorRendering (round 1)
a478140993 merge of origin/main (e476193bf5)
c6b8824360 refactor(mobile): one walk for every source census, without build output
a033367d55 docs(mobile): say why the pin lives in the module without misstating what typechecks tests (pullfrog; comment only)

Verification

Lead gate on a478140993 (round-1 folds + merge of main) against e476193bf5: tsc 0, ratchet 0, oxlint 0, oxfmt 0, changed-code quality 0, react-doctor 0, oxlint-config 0, anti-slop 0, merge-max-lines 0, root oxlint over 12 changed files 0, root oxfmt over 6 files 0, machine paths 0; config/scripts 237 files / 2,140 passed, 0 failed; mobile 770 files / 8,605 passed, 0 failed. Lead control at that head: the config spliced raw into the native inline script → mermaid-diagram-html.test.ts fails does not let a config value break out of the inline script either (1 of 6).

Lead gate on 26536f7066 against 30f2bc60f9 (verify-gates.sh, all four postinstall artifacts rebuilt): tsc 0, tests-typecheck ratchet 0, oxlint 0, oxfmt 0, changed-code quality 0, react-doctor 0, oxlint-config 0, anti-slop 0, merge-max-lines 0, root oxlint over 11 changed files 0, root oxfmt over 6 files 0, machine paths 0; config/scripts 236 passed + the known owner-loss timing flake (green alone, 21/21); mobile 770 files / 8,604 passed, 0 failed. Lead control: the engine loaded by a static import instead of import() → mobile-web-app-session-terminal-closure.test.mjs fails reaches the engine as one deferred module and never as part of the download (1 of 3).

Lead gate on c6b8824360 against e476193bf5 (verify-gates.sh, all five postinstall artifacts rebuilt): tsc 0, ratchet 0, oxlint 0, oxfmt 0, changed-code quality 0, react-doctor 0, oxlint-config 0, anti-slop 0, merge-max-lines 0, root oxlint over 22 changed files 0, root oxfmt over 6 files 0, machine paths 0; config/scripts 237 files / 2,140 passed, 0 failed; mobile 771 files / 8,609 passed, 0 failed. Lead reproduction: nine test files import census-source-files.

Follow-up recorded, not in this PR: a mobile/generated/ home for executable build output would remove the exclusion list entirely.

Not in this PR: the HTML preview (#21862), haptics (#21864), dictation (PR D), the rich editor (C1/C2), the img-src widening (ruling 27).

Red-first for C7.10 item B. The check mounts the real web sibling in
chromium and webkit under the shipped shell CSP and asks four things of
it: that a diagram renders with zero policy violations and zero eval /
new Function calls, that the SVG is the native buildHtml's own output
once the diagram id and xmlns:xlink are normalised away, that a hostile
diagram lands inert, and that a source change, an unmount and a remount
leave exactly one SVG and no listener of the first mount.

The equality oracle is buildHtml itself, bundled for Node behind a
Proxy stub for its native imports and served as its own document in the
same browser, so neither side of the comparison is retyped.

All eight cases fail on this commit: the sibling is still the labelled
source box.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Ruling 28. mobileWebAppRouteClosure reads metafile.inputs, which holds
dynamically imported modules under splitting: true exactly as it does
under splitting: false, so it cannot say "on demand" about anything: an
on-demand mermaid moves the session route's module list 4320 -> 6362
while its download does not move at all.

So the fence moves to entryStaticClosure. The new helper walks the
emitted chunks from the output the route's own module landed in and
follows import-statement edges only, and hands back both halves, because
mermaid's absence from the download is only a measurement while its 66
files are present in the deferred half.

The module list's new total is recorded in the docstring with its reason
and asserted beside the engine's own file count, which moves only when
the pinned mermaid version does.

Red on this commit: no mermaid in the closure yet.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The web sibling stops being a source box. mermaid is a browser library,
so the page imports it inside the render effect and draws the diagram in
this document: no WebView, no 3.7 MB engine string, and nothing of the
engine downloaded by a session with no diagram on it.

What replaces the sandbox is mermaid's own securityLevel: 'strict',
which runs its serialized SVG through DOMPurify. The native path's
</script> escaping has no analogue here and needs none, because the
source is a JS string argument rather than text spliced into an inline
script. Measured in both engines: a script in a label, a </script>, an
onerror and a javascript: click all land inert.

The configuration is now one object both hosts read, so the theme cannot
drift between the page and the phone; buildHtml serializes it instead of
holding a second copy. It gains suppressErrorRendering, because mermaid
otherwise draws its own error diagram into a temporary element and leaves
that element behind when it rethrows -- an orphan SVG on the page, and on
native a diagram the component is about to replace with the source box
anyway.

The dispose clears the host on unmount and on a source change; the id is
a useId, because mermaid writes it into the stylesheet inside the SVG and
it has to be a CSS identifier.

Also re-records the closure total the previous commit pinned: with the
real component the session route's module list is 6376, not the design
probe's 6362, and the reason is in that file's docstring.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Putting mermaid on the page took the app bundle from 69 emitted scripts
to 172, and the asset budget failed: 215 assets against a ceiling of
115. The cause is not a page split running away, which is what that
ceiling is for -- it is that mermaid lazily imports each of its own
diagram types, so one import() lands 103 scripts no route count
predicts.

So the ceiling gains a second term, named and measured (172 scripts with
mermaid against 69 with it aliased to a stub, at 11.17.2), rather than
the route term being raised to cover it. A page split running away still
fails on the route term, and the failure still says which of the two
grew.

The consequence is worth reading twice: the derived ceiling has to stay
inside the 256 assets the shell will load, and with 42 images it now
crosses that at 24 routes instead of 50. The bundle is at 215 today with
14 routes, so there is room for about ten more routes before a green
build produces a manifest no phone will open.

Measured by the config/scripts suite failing on this head, not predicted.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
import('mermaid') from inside the app bundle emitted 103 scripts, not
one: mermaid lazily imports each of its own diagram types and esbuild
splits along those boundaries. Every one of those scripts sits inside
the OTA generation the phone has already downloaded, so the split moved
no bytes over the wire and spent 103 of the 256 manifest assets the
shell will load -- which is the scarce resource here, and the reason the
previous commit had to invent a second ceiling term.

So a sibling generator bundles the package into one ESM module beside
the WebView engine it already builds, emitted by the same postinstall
run, gitignored and lint-ignored with the others. The page imports that
artifact on demand instead, through a loader whose return type names the
two calls the component makes -- checked against the artifact's own
inferred export rather than cast to it.

Measured, at 14 routes:

  emitted scripts   172 -> 69   (68 with no deferred engine at all)
  manifest assets   215 -> 112  (111 with none)
  session modules  6376 -> 4323 (+3 over main: config, loader, artifact)
  chunks fetched for one graph TD   27 -> 1
  bytes fetched      837,530 -> 3,482,965

The static-closure fence is unchanged in meaning and now reads on the
artifact: absent from every chunk the route reaches by an import
statement, present in the deferred half. The rendered SVG is byte-for-
byte what it was, so the equality against the native document still
holds on both engines.

Also adds the diagram to the webview-consumers list, which is what that
list means: its native component imports the package and its sibling is
what the builder resolves instead.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
With the engine pre-bundled into one artifact the bundle emits 69 scripts
at 14 routes against the route term's 72, so the second term this series
added has nothing left to do and the route count is the only term again.
mobileWebAppBundleMaxChunks and the asset ceiling derived from it are
back to what main has; the shell's 256 assets are crossed at 50 routes
again rather than at 24.

What stays is why. A ceiling raised to admit 172 scripts would have
admitted any split at all, so the budget test gains the control that
holds the line: the single-artifact count passes the ceiling and the
lazily-chunked count fails it, both measured at 14 routes, with mermaid
named as what produced the second.

Red before the term came out: the control failed asserting 172 > 175.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The census walks mobile/src for AST reaches into the unvalidated request
port, and the pre-bundled mermaid artifact is the first generated file
under src that is executable code rather than a string literal. Two of
its own vendored dependencies contain the token `sendRequest`, so the
walk read minified third-party code as a new call site and asked for an
inventory line nobody can ever migrate.

So `*.generated.ts` joins node_modules and test files in that file's
stated list of what it does not scan, with the reason. The scripts that
emit those artifacts are ordinary source and are still scanned, which is
where a real reach would be.

Two halves to the new control, because a filter that skipped everything
would satisfy either alone: nothing generated is left in the scan, and
the matcher still finds the port when handed one line of code.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

Warning

Review limit reached

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: dc61bc24-49e1-4076-afb1-5aa83070c228

📥 Commits

Reviewing files that changed from the base of the PR and between a033367 and e5b144f.

📒 Files selected for processing (27)
  • config/scripts/build-mobile-web-app-bundle.test.mjs
  • config/scripts/mobile-web-app-mermaid-render.test.mjs
  • config/scripts/mobile-web-app-route-chunk-closure.mjs
  • config/scripts/mobile-web-app-session-terminal-closure.test.mjs
  • config/scripts/mobile-web-app-session-webview-consumers.test.mjs
  • config/scripts/verify-mobile-web-app-bundle.mjs
  • mobile/.gitignore
  • mobile/.oxlintrc.json
  • mobile/package.json
  • mobile/scripts/build-mermaid-page-engine.mjs
  • mobile/src/components/pr-sidebar/MermaidDiagram.tsx
  • mobile/src/components/pr-sidebar/MermaidDiagram.web.tsx
  • mobile/src/components/pr-sidebar/mermaid-diagram-config.ts
  • mobile/src/components/pr-sidebar/mermaid-diagram-html.test.ts
  • mobile/src/components/pr-sidebar/mermaid-page-engine.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-flag-census.test.ts
  • mobile/src/reanimated-web-mapper-deps.test.ts
  • mobile/src/rpc-params-contract-type-only-boundary.test.ts
  • mobile/src/test-support/census-source-files.test.ts
  • mobile/src/test-support/census-source-files.ts
  • mobile/src/transport/lifecycle-owner.test.ts
  • mobile/src/transport/rpc-operation-cast-fence.test.ts
  • mobile/src/transport/rpc-subscription-boundary.test.ts
  • mobile/src/transport/timer-receiver-census.test.ts
  • mobile/src/transport/unchecked-rpc-reader-boundary.test.ts
  • mobile/src/transport/unvalidated-rpc-request-port-boundary.test.ts
  • mobile/web-entry/web-overrides.json

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e10ea1b2-3e78-46ea-a307-6790a54224ef

📥 Commits

Reviewing files that changed from the base of the PR and between c6b8824 and a033367.

📒 Files selected for processing (1)
  • mobile/src/components/pr-sidebar/mermaid-page-engine.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • mobile/src/components/pr-sidebar/mermaid-page-engine.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The web MermaidDiagram now renders sanitized Mermaid SVGs with a lazily loaded, pre-bundled engine. Native and web rendering share one configuration. Chromium and WebKit tests verify SVG parity, CSP compliance, lifecycle cleanup, hostile-input handling, and fallback behavior. Route-closure tests classify the engine as one deferred artifact. Bundle budgets now use 69 chunks for 14 routes. Shared census utilities exclude generated files from boundary tests.

Priority: ➖ Normal

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 36 functions across 23 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description gives detailed technical context, rationale, testing results, and scope boundaries. However, it does not follow several required template sections. It omits the mandatory linked issue,… Add the required template sections. Include a valid Fixes #... issue reference, attach before-and-after visual proof or state N/A with a reason, document manual and automated testing with tested platforms, complete the AI Disclosure sec…
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the primary change: Mermaid diagrams now render on mobile web using one deferred engine artifact. The scope and project references add context without making the title mis…
Full details: Description check

Explanation

The description gives detailed technical context, rationale, testing results, and scope boundaries. However, it does not follow several required template sections. It omits the mandatory linked issue, visual proof for a UI change, explicit testing checklist and platform details, and the remaining checklist sections.

Resolution

Add the required template sections. Include a valid Fixes #... issue reference, attach before-and-after visual proof or state N/A with a reason, document manual and automated testing with tested platforms, complete the AI Disclosure section when applicable, and complete the Review, Agent skill upstream boundary, Notes, and Checklist sections.

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
mobile/src/components/pr-sidebar/MermaidDiagram.web.tsx (1)

53-53: 🔒 Security & Privacy | 🛡️ Analyzed with Security Review | 🔵 Trivial | ⚡ Quick win

Expand the hostile Mermaid fixture.

Add cases for configuration directives and embedded elements. Assert that both Chromium and WebKit produce no active elements or side effects. The current evidence supports broader regression coverage, not an independent source sanitizer: strict mode encodes HTML and protects securityLevel from diagram directives.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 57581485-9cdf-4a87-aa2d-dff7b26715bd

📥 Commits

Reviewing files that changed from the base of the PR and between e476193 and 26536f7.

📒 Files selected for processing (16)
  • config/scripts/build-mobile-web-app-bundle.test.mjs
  • config/scripts/mobile-web-app-mermaid-render.test.mjs
  • config/scripts/mobile-web-app-route-chunk-closure.mjs
  • config/scripts/mobile-web-app-session-terminal-closure.test.mjs
  • config/scripts/mobile-web-app-session-webview-consumers.test.mjs
  • config/scripts/verify-mobile-web-app-bundle.mjs
  • mobile/.gitignore
  • mobile/.oxlintrc.json
  • mobile/package.json
  • mobile/scripts/build-mermaid-page-engine.mjs
  • mobile/src/components/pr-sidebar/MermaidDiagram.tsx
  • mobile/src/components/pr-sidebar/MermaidDiagram.web.tsx
  • mobile/src/components/pr-sidebar/mermaid-diagram-config.ts
  • mobile/src/components/pr-sidebar/mermaid-page-engine.ts
  • mobile/src/transport/unvalidated-rpc-request-port-boundary.test.ts
  • mobile/web-entry/web-overrides.json

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

buildHtml spliced JSON.stringify(MERMAID_DIAGRAM_CONFIG) straight into
the inline <script>, twenty lines below the function that exists because
JSON.stringify leaves `<`, `>`, `&` and the U+2028/9 separators raw. Inert
at today's five hex colours, and not inert for a themeCSS or a font stack,
which is free text going into the same script element.

So the escaping splits from the stringify and both callers use it: the
source keeps its own wrapper, the config gets one. Those characters only
ever appear inside JSON string literals, so escaping them is valid for an
object serialization exactly as it is for a string.

Red first: a config carrying `</script><script>` put four raw closers in
the document where a benign build has two.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The loader returned the artifact's default as PageMermaid, which checked
that two names exist and nothing about their shapes: the artifact is
minified vendor output and both members infer as `any` there -- a probe
assigning engine.render to a number compiles -- and `any` satisfies every
signature there is.

So the shapes are asserted against the package's `Mermaid`, which is
precise. A PageMermaid member whose signature the engine does not really
have now fails at this line rather than at a call the page makes.

In the product module, not a test: mobile/tsconfig.json excludes test
files, so a type-only assertion in one is never compiled. Underscored
because it is a compile-time statement with no runtime reader, which is
the form the linter asks for.

Control, verified both ways: changing render to (id: number) => Promise<{
svg: number }> reds tsc naming both parameter and return, and the real
signatures compile.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The four-point series was stale and read as a slope it is not. Measured
again on this head, by copying the route tree and dropping routes from
the end of the sorted key list -- both siblings of each, because deleting
a .web.tsx alone leaves the native file for the builder to resolve and
measures an entirely different closure, which is how the first attempt
at this produced 77 scripts for 14 routes:

  8 routes  -> 32 scripts
  10 routes -> 43
  12 routes -> 61
  14 routes -> 69   (the real tree)

Between four and nine more per route depending on which route, so 4r + 16
is a bound and not a fit, and the justification now says that instead of
claiming three per route. It also says the part that matters more: at 14
routes the tree measures 69 against 72, and the last two routes cost the
8 the ceiling grants for two. The fence is at break-even, and the new
assertion states that slope from the function rather than from a comment.

Also records what the generation weighs, since every chunk ships in it
whether or not a phone fetches one: 8,016,714 bytes across 112 assets
against the 9 MiB ceiling, 84.9%, 1,420,470 left. It was 4,539,090 before
item B, and the engine is the difference.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The shared config reaches the phone too, and it gained a key the native
path did not have. So the native document is now loaded for a diagram
that throws, in both engines, with window.ReactNativeWebView standing in
for the host: mermaid's run still rethrows, the document's own catch
still posts `error`, and that is the message the component turns into the
source box.

Measured both ways, so the case says which half the key owns. Whether
the fallback fires does not depend on it -- `error` is posted with the
key and without it. What depends on it is that nothing is drawn behind
the fallback: removing the key leaves mermaid's own error diagram in the
document and reds this case at 1 SVG against 0, on chromium and webkit
alike.

The control is the same document for a diagram that parses: a height,
not `error`, and one SVG.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • The page renders the diagram — MermaidDiagram.web.tsx replaces the labelled source box with a deferred import() of a pre-bundled engine, renders via mermaid.render, writes the sanitized SVG into the React-owned host, and keys its fallback on failedSource === source so a new source recovers.
  • One shared configuration — mermaid-diagram-config.ts holds the object both hosts read; native buildHtml now JSON.stringifys it and gains suppressErrorRendering, which matches the fallback it already renders.
  • One deferred engine artifact — build-mermaid-page-engine.mjs bundles mermaid once (splitting: false) into the gitignored mermaid-page-engine.generated.ts; mermaid-page-engine.ts loads it with a named return type rather than a cast. This keeps import('mermaid')'s 103 lazy diagram-type chunks out of the shell's 256-asset budget.
  • Fences and censuses — new mobile-web-app-route-chunk-closure.mjs walks emitted chunks on import-statement edges only; the session closure test pins the engine out of the download and into the deferred half; the budget test gains a chunked-engine control; the raw-request-port census carves out *.generated.ts with a two-part control.
  • Browser proof — new mobile-web-app-mermaid-render.test.mjs measures CSP violations, JIT, hostile-fixture inertness, fallback/recovery and byte-equality against native buildHtml in Chromium and WebKit under the shipped policy.

Two lenses I could not answer from the diff alone were dispatched and both cleared: mermaid securityLevel: 'strict' output is inert at this call site for the pinned DOMPurify, and mermaid 11.17.2's public render serializes internally on a module queue, so the page's per-instance concurrent render calls are safe without the desktop renderer's explicit queue (whose DOM-clobber comment no longer describes 11.x). No blocking or actionable findings at 26536f70.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Nine censuses under mobile/src each held a copy of the same recursive
walk, and each decided for itself what a source file is: seven had no
opinion about generated files, one excluded them in its own regex, and
one had the exclusion I added last round. So all nine read 7.9 MB of
emitted vendor code -- 3.7 MB of mermaid for the WebView, 3.5 MB of it
for the page -- and the two largest censuses TypeScript-parsed all of it,
looking for call sites nobody wrote and nobody can move.

That is what took rpc-params-contract-type-only-boundary over its 5 s
timeout in CI once the fifth artifact arrived. Measured here, median of
3, import plus tests:

  main, 4 artifacts, no exclusion   1004 ms   (slowest case  831 ms)
  with the 5th, no exclusion        1513 ms   (slowest case 1358 ms)
  with the 5th, this commit          947 ms   (slowest case  788 ms)

So it lands below where main has it, not merely below where I left it.
Across the nine, four more halve: rpc-operation-cast-fence 769 -> 441,
rpc-subscription-boundary 946 -> 468, unchecked-rpc-reader-boundary
1042 -> 538, lifecycle-owner 747 -> 433, reanimated-web-mapper-deps
1028 -> 516. The two that already excluded generated files do not move.

What each census counts as interesting -- extensions, whether test files
are in -- stays its own, because they genuinely disagree. What counts as
a source file at all is now said once.

The control is the file that started it: a *.generated.ts whose text
holds exactly the import a census is hunting, planted beside an ordinary
file carrying the same text. The generated one is not returned and the
ordinary one is, so the absence is a measurement. A second control reads
mobile/.gitignore and holds the predicate to every artifact the tree
generates, and a third fences the walk itself to one spelling, so a tenth
census cannot paste the cost back in.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one comment-only correction inline.

Reviewed changes

Re-reviewed the six commits since the prior pullfrog review at 26536f70 (round-1 folds, a merge of main, and one refactor), reading the incremental range-diff and the full PR diff.

  • Escaped the shared config into the native document's inline script — MermaidDiagram.tsx routes both the source and MERMAID_DIAGRAM_CONFIG through encodeJsonForScript, so a config value containing </script> (a future themeCSS or font stack) can no longer close the inline script; a mocked-config test pins both the source and config splices.
  • Pinned the page engine's type against the package's own — mermaid-page-engine.ts adds a compile-time Mermaid → PageMermaid assignment, since the minified artifact's members infer as any.
  • Re-measured the chunk series and recorded the generation byte total — the budget test and verify-mobile-web-app-bundle.mjs docs replace the old 23/40/47/53 readings with 32/43/61/69, state the method, and note the fence is at break-even (69 against 72 at 14 routes).
  • Pinned the native fallback under suppressErrorRendering — the render test loads a native-broken.html document and asserts it posts error with zero SVGs, against a parsing control.
  • Consolidated nine source censuses onto one shared walk — new census-source-files.ts replaces each per-test copy of the walk and excludes every *.generated.tsx?; census-source-files.test.ts plants a violating generated file, checks the artifact list read from mobile/.gitignore, and asserts one spelling of the walk remains.

I verified the census refactor is behavior-preserving (same extension/test filters at each call site, plus the generated-file exclusion), the config escaping is sound for both splice sites, and the budget assertions hold arithmetically. No new behavioral issues found.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Jinwoo-H and others added 2 commits September 20, 2026 23:16
The comment said a type-only pin in a test file "is never compiled".
That is false: mobile/tsconfig.json excludes *.test.ts, but
tsconfig.test.json is a second program that does check them, run by
check:tests-typecheck and held by the tests-typecheck ratchet.

The conclusion is unchanged and the reason is now the true one. The app's
own typecheck is the unconditional gate and would not cover a pin written
in a test; the test program is real but carries a grandfathered baseline
and a few files held outside it on purpose. And the assertion is about
this module's own type either way, so it belongs beside it.

Comment only; tsc, the ratchet and both lints re-run on the file.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
@Jinwoo-H
Jinwoo-H merged commit e9b1806 into main Sep 21, 2026
32 checks passed
@Jinwoo-H
Jinwoo-H deleted the ota-c7-10b-mermaid branch September 21, 2026 04:36
Jinwoo-H added a commit that referenced this pull request Sep 21, 2026
…page closure (#21908)

#21864 (haptics on the page) and #21871 (mermaid on the page) were each
green against a main that lacked the other. Together, `haptics.web.ts`
reaches `bridge-haptics-notify.ts` inside the session route's closure, so
the module pin recorded by #21871 reads 4324 on main, not 4323. Pin the
measured count and name the module.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Jinwoo-H added a commit that referenced this pull request Sep 21, 2026
Main at 2d697a4, which carries #21908's re-pin of the session route's module
count. One conflict, the pin itself, plus `27a0889dcf`'s relay test arriving
unconflicted.

Resolved by keeping this branch's `SESSION_ROUTE_MODULES = 4284` and folding
#21908's account into the one explanation the docstring already holds. Re-measured
on the merged tree with the four postinstall generators run first rather than
carried over: 4284 modules, 934 local, with
`src/mobile-web-shell/bridge/bridge-haptics-notify.ts` read out of the closure by
name rather than inferred from the total.

What #21908 adds to the account, and what this branch could not say on its own:
C7.10 item E (#21864) and mermaid (#21871) were each green against a main that
lacked the other, which is how main came to hold 4323 while measuring 4324. The
module reaches this branch's 4284 by that same route and not by anything this
branch did. The constant's own comment is now the short form and points at the
docstring, so the two explanations read once rather than twice.

Nothing under `mobile/` moves in this merge. It changes exactly two files here,
the closure test and `src/relay/omp-fresh-launch-environment.test.ts`, so the
mobile suite is not re-run; mobile tsc is, and is clean.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant