Skip to content

fix(wasm): textSetFontWeight sets the size and the weight (#14740) - #14746

Merged
TheHypnoo merged 2 commits into
PerryTS:mainfrom
raliclo:fix/14740-web-font-weight
Nov 16, 2026
Merged

TheHypnoo merged 2 commits into
PerryTS:mainfrom
raliclo:fix/14740-web-font-weight

Conversation

@raliclo

@raliclo raliclo commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

textSetFontWeight(widget, size, weight) set CSS font-weight to the size on --target web and dropped the weight, because ui_method_map.rs routed it to the 2-argument perry_ui_set_font_weight(h, weight). It now has its own 3-argument bridge that applies both.

Changes

  • crates/perry-codegen-wasm/src/emit/ui_method_map.rs: textSetFontWeight maps to the new perry_ui_text_set_font_weight (the name perry-dispatch's ui_table uses); setFontWeight / set_font_weight keep the 2-argument perry_ui_set_font_weight.
  • crates/perry-codegen-wasm/src/wasm_runtime.js: perry_ui_text_set_font_weight(h, size, weight) sets font-size: <size>px and font-weight. A weight in 0..1 is the native scale (Apple's systemFont(ofSize:weight:), as in perry-styling's applyFontBold(h, size) → weight 1.0, and the docs' textSetFontWeight(bold, 20, 1.0)) and maps onto CSS 100..900 the way the HarmonyOS backend (perry-codegen-arkts/src/mutations.rs) maps it; a value above 1 (the docs' textSetFontWeight(font, 24, 700)) is used as a CSS weight, capped at 1000.
  • A test in crates/perry-codegen-wasm/src/emit/tests.rs that reads the widget's DOM style. It brings the WIDGET_DOM / run_web_ui_source_then helpers verbatim from fix(web-ui): Toggle passes a boolean to onChange #14691 (same text as fix(web-ui): Picker(onChange) receives its callback #14692–fix(web-ui): tableUpdateRowCount re-renders the table body #14695), so whichever merges first the others conflict only trivially.

Related issue

Fixes #14740

Test plan

  • cargo test -q -p perry-codegen-wasm --lib: 77 passed. With only the fix reverted (test kept), text_set_font_weight_applies_the_size_and_the_weight fails: left "A undefined 28\nB undefined 16\nC undefined 12", right "A 28px 700\nB 16px 900\nC 12px 500".
  • cargo build-perry --release && scripts/gc_call_effects/sidecars.sh target/release, npm ci (one build carrying this and the wasm/web: obj.message reads "" on any non-Error object (lowered to error_message) #14739 fix), A/B against a build of main 64257c3: python3 scripts/parity.py run language/error|language/object|language/class --mode web passes the same cases on both (5/32, 45/429, 75/571); bash tests/integration/wasm/run_wasm_tests.sh 30 passed, 3 failed (04_functions, 10_higher_order, 19_ffi_imports) on both.
  • rustfmt clean on the touched files; cargo clippy -p perry-codegen-wasm reports nothing in them; BASE_SHA=upstream/main scripts/run_lint_gates.sh FAIL set identical to main's.

The backends disagree on the 0..1 scale (macOS passes it to NSFontWeight directly, GTK and Android bold at ≥ 0.5, HarmonyOS maps it onto 100..900); this follows HarmonyOS because it is the backend that also targets a 100..900 weight. The --target js web runtime (perry-codegen-js) has the same 2-argument routing and is not changed here.

  • cargo build --release clean
  • Added a #[test] in the affected crate

Checklist

  • I have NOT bumped the workspace version or edited CHANGELOG.md (maintainer handles these at merge)
  • My commits follow the loose feat: / fix: / docs: / chore: prefix convention used in the log
  • I've read CONTRIBUTING.md and agree to the Code of Conduct

🤖 Generated with Claude Code

https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p

Summary by CodeRabbit

  • New Features
    • For web apps, textSetFontWeight now applies both the requested font size and font weight. Weight values from 0 to 1 map to CSS weights from 100 to 900; values greater than 1 are used as CSS weights, capped at 1000.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Walkthrough

For --target web, textSetFontWeight now sets both font size and font weight. The runtime maps fractional weights to CSS weights from 100 through 900 and uses weights above 1 as CSS weights, capped at 1000. The web test harness includes a widget-capable DOM to verify the resulting styles.

Changes: Web text font weight

Layer / File(s) Summary
Route and verify text font weight
crates/perry-codegen-wasm/src/emit/ui_method_map.rs, crates/perry-codegen-wasm/src/wasm_runtime.js, crates/perry-codegen-wasm/src/emit/tests.rs, changelog.d/14746-web-text-font-weight.md
textSetFontWeight maps to a dedicated runtime function. The function sets font size and maps the weight to CSS; widget tests check weights 700, 1.0, and 0.5. The changelog documents the web behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: thehypnoo

Merge Risk: Minimal · previous review bb6c7

On the web target, textSetFontWeight now sets both font size and font weight as intended. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (textSetFontWeight now sets both size and weight) and the affected area (wasm). It matches the main change in the changeset. The title also includes the issue number, which is …
Description check Passed The description follows the template sections: Summary, Changes, Related issue, Test plan, and Checklist. The Summary explains the bug and the fix. Changes lists the affected files. The Related issue …
Linked Issues check Passed Issue #14740 requires that textSetFontWeight(widget, size, weight) set the CSS font size from size and the font weight from weight on --target web. At the reviewed head, ui_method_map.rs rou…
Out of Scope Changes check Passed All changes connect to #14740. The method-map split and the new perry_ui_text_set_font_weight bridge are the direct fix. The wasm_runtime.js change is limited to that bridge and its dispatch entry…
Full details: Title check

Explanation

The title names the fix (textSetFontWeight now sets both size and weight) and the affected area (wasm). It matches the main change in the changeset. The title also includes the issue number, which is acceptable.

Full details: Description check

Explanation

The description follows the template sections: Summary, Changes, Related issue, Test plan, and Checklist. The Summary explains the bug and the fix. Changes lists the affected files. The Related issue is filled in (Fixes #14740). The Test plan gives commands and results. The checklist items are marked. The template's test-plan items for docs and the workspace test command are not explicitly addressed, but the description is mostly complete.

Full details: Linked Issues check

Explanation

Issue #14740 requires that textSetFontWeight(widget, size, weight) set the CSS font size from size and the font weight from weight on --target web. At the reviewed head, ui_method_map.rs routes textSetFontWeight to the new perry_ui_text_set_font_weight (diff confirmed). wasm_runtime.js defines that bridge with three arguments. It sets el.style.fontSize = size + "px" and sets el.style.fontWeight from weight. A value above 1 is used as a CSS weight, capped at 1000. So textSetFontWeight(t, 28, 700) yields 28px and weight 700, which matches the issue example. The bridge is also added to __perryUiDispatch. The setFontWeight / set_font_weight names keep the two-argument bridge, so the reported bug is fixed without changing those callers. The added test in emit/tests.rs was not inspected directly. The PR reports that it fails when only the fix is reverted and that the suite passes (77 tests). That report is accepted as author evidence, not independently verified.

Full details: Out of Scope Changes check

Explanation

All changes connect to #14740. The method-map split and the new perry_ui_text_set_font_weight bridge are the direct fix. The wasm_runtime.js change is limited to that bridge and its dispatch entry. The changelog fragment in changelog.d/ documents the behavior change. The emit/tests.rs changes add DOM test helpers and a regression test that exercise the fix. The helpers are reported as copied from #14691, which is a test-support choice, not unrelated behavior. The weight mapping follows the HarmonyOS backend, as the PR describes. The --target js runtime is not changed, and the PR states this explicitly. No unrelated functional change was found in the reviewed diffs.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4c7ccdd2-d29e-4852-a24c-38408e7040fc
Commits

Reviewing files that changed from the base of the PR and between 64257c3 and bb6c7cb.

Files selected for processing: 4

  • changelog.d/14746-web-text-font-weight.md
  • crates/perry-codegen-wasm/src/emit/tests.rs
  • crates/perry-codegen-wasm/src/emit/ui_method_map.rs
  • crates/perry-codegen-wasm/src/wasm_runtime.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

TheHypnoo pushed a commit to raliclo/perry that referenced this pull request Nov 16, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
@TheHypnoo
TheHypnoo force-pushed the fix/14740-web-font-weight branch from bb6c7cb to 5b00620 Compare November 16, 2026 14:01
ralic and others added 2 commits November 16, 2026 16:36
)

`textSetFontWeight(widget, size, weight)` was routed to the 2-argument
`perry_ui_set_font_weight(h, weight)`, so on `--target web` the size became
the CSS font-weight and the weight was dropped. It now has its own bridge
that sets `font-size` from the size and `font-weight` from the weight; a
weight in 0..1 (the native scale, `systemFont(ofSize:weight:)`) maps onto
CSS 100..900 as the HarmonyOS backend maps it, and a larger value is taken
as a CSS weight. The widget method `setFontWeight(weight)` keeps the
2-argument bridge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
@TheHypnoo
TheHypnoo force-pushed the fix/14740-web-font-weight branch from 5b00620 to 863d6b3 Compare November 16, 2026 15:36
@TheHypnoo
TheHypnoo merged commit fd6d901 into PerryTS:main Nov 16, 2026
6 checks passed
@raliclo
raliclo deleted the fix/14740-web-font-weight branch November 17, 2026 01:36
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.

wasm/web: textSetFontWeight(w, size, weight) sets font-weight to the size and drops the weight

3 participants