Skip to content

Fix webapp issue for Safari browser - #2246

Merged
findolor merged 31 commits into
mainfrom
2025-10-19-safari-issue-fix
Oct 30, 2025
Merged

Fix webapp issue for Safari browser#2246
findolor merged 31 commits into
mainfrom
2025-10-19-safari-issue-fix

Conversation

@rouzwelt

@rouzwelt rouzwelt commented Oct 19, 2025

Copy link
Copy Markdown
Contributor

Motivation

fixes #2029
fixes #2213

There was an issue with safari browser for webapp that it errors on startup with unintiailized variable, this PR fixes that.

the issue is caused by Safari bug, that it cant handle top-level-await specially when it is imported multiple times in multiple modules., for more read about this:
sveltejs/kit#7805

In order to fix this issue, we need to update SvelteKit to latest version where ClientInit hook feature is available, this hook allows to do some asynchronous task before the web app is loaded and rendered. and we need to remove the top-level-await in orderbook wasm package build script, provide a function initialization of the orderbook wasm module and initialize it in the ClientInit hook.

To fix this, we ended up with workaround/hack solution, which is to make a think wrapper wasm crate that initializes the js_api (or any other big wasm crate) on start using wasm_bindgen(start) attribute, then on the build script for js_api web bindings (this is only on web/esm, no limitation for node/cjs bindings so we don't need to touch that), we need to append a custom fn that initializes the js_api wasm module with a try/catch, first trying sync and if it fails try async. This works because chrome error on wasm sync init when the size is over 8MB, which can be catched and then init async, but on safari the async init doesn't work at all but the sync init succeeds so we never will reach to async init.
On any other browser or environment such as node with ES6, this should work fine because first the sync init is tried.

Using rust profile release flags (created release-wasm custom profile), we were able to reduce the wasm size down to 4.85 MB, which leaves us with plenty of room for more features that might be added in future, although if at any point we hit the 8Mb limit, we can use the wrapper solution in case Safari bug is not resolved by then.

  • Note1: Added a simple script to check the wasm artifact size that gets executed on check and build command for orderbook pkg, which will throw an error if we ever hit 8MB limit.

  • Note2: using the heavy size optimizations caused WasmEncodedError and WasmEncodedResult ts type bindings to be duplicated in the generated .d.ts, so needed to add a piece of script to dedupe them.

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • Chores
    • Restructured the build to per-package CJS/ESM builds with per-package size checks for faster iteration.
    • Optimized WebAssembly compilation using a size-focused release profile to produce smaller artifacts.
    • Simplified dev/build commands for web and desktop app workflows to skip monorepo build steps.
    • Added automated WASM bundle size validation to prevent oversized releases.

@rouzwelt rouzwelt self-assigned this Oct 19, 2025
@coderabbitai

coderabbitai Bot commented Oct 19, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Refactors orderbook build to emit per-package CJS/ESM artifacts with base64-packed wasm JSON, adds an 8 MB wasm size check, introduces a release-wasm Cargo profile and targeted wasm build for rain_orderbook_js_api, and removes tauri/monorepo pre-build invocations from npm scripts.

Changes

Cohort / File(s) Summary
Orderbook package manifest
packages/orderbook/package.json
Removed build-tauri; updated build to run rm-dist, rm-temp, build-wasm (now targeted), TS build script, and check; build-wasm now builds with --profile release-wasm -p rain_orderbook_js_api.
Per-package build orchestration
packages/orderbook/scripts/build.js, packages/orderbook/scripts/buildPackage.js, packages/orderbook/scripts/sizeCheck.js
Reworked build to iterate packages and call exported buildCjs(pkg) and buildEsm(pkg); added sizeCheck(pkg) enforcing an 8 MB wasm limit; added DTS deduplication; emit CJS/ESM wrappers that load base64-packed wasm JSON bundles.
Web & Tauri manifests
packages/webapp/package.json, tauri-app/package.json
Removed pre-build monorepo orderbook invocations from dev/build scripts; webapp now runs Vite directly; tauri-app build/dev scripts simplified and no longer invoke build-tauri -w @rainlanguage/orderbook.
Cargo and flake build config
Cargo.toml, flake.nix
Added [profile.release-wasm] with size-optimized settings (opt-level="z", lto=true, strip=true, panic="abort", codegen-units=1, etc.); flake.nix changed to perform a targeted build of rain_orderbook_js_api using the new profile instead of a workspace-wide build.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CLI as npm / CI
  participant BuildJS as packages/orderbook/scripts/build.js
  participant PackBuilder as packages/orderbook/scripts/buildPackage.js
  participant SizeCheck as packages/orderbook/scripts/sizeCheck.js
  participant Cargo as cargo (release-wasm)

  CLI->>BuildJS: npm run build
  BuildJS->>Cargo: (pre-step) cargo build --profile release-wasm -p rain_orderbook_js_api
  BuildJS->>PackBuilder: buildCjs(pkg)
  PackBuilder->>PackBuilder: wasm-bindgen -> CJS wrapper + base64 JSON
  BuildJS->>PackBuilder: buildEsm(pkg)
  PackBuilder->>PackBuilder: wasm-bindgen -> ESM wrapper + base64 JSON
  BuildJS->>SizeCheck: sizeCheck(pkg)
  SizeCheck-->>BuildJS: pass / throw if > 8MB
  BuildJS->>CLI: run TS build & npm checks
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Focus areas:
    • packages/orderbook/scripts/buildPackage.js — DTS deduplication, wrapper generation, JSON wasm bundling.
    • packages/orderbook/scripts/build.js — per-package orchestration and integration with sizeCheck.
    • Cargo.toml / flake.nix — correctness of release-wasm profile and targeted build invocation.
    • packages/orderbook/package.json and other package scripts — ensure CI/npm lifecycle compatibility.

Possibly related PRs

Suggested labels

rust, general update

Suggested reviewers

  • hardyjosh
  • 0xgleb
  • hardingjam

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Fix webapp issue for Safari browser" directly aligns with the stated objective to fix Safari startup errors (issues #2029 and #2213) caused by a Safari-specific bug with top-level await handling. The changes across the codebase—including the new release-wasm profile for WASM optimization, deduplication logic for TypeScript bindings, the WASM size checking script, and simplified build workflows—all support this central Safari fix objective. While the title does not enumerate the implementation details (build optimization, deduplication, size limits), titles are not expected to cover every detail; they should highlight the primary goal, which this title does clearly and specifically without being vague or misleading.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2025-10-19-safari-issue-fix

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6af302 and 5acb848.

📒 Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • flake.nix (1 hunks)
  • packages/orderbook/package.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/orderbook/package.json
🧠 Learnings (29)
📓 Common learnings
Learnt from: brusherru
PR: rainlanguage/rain.orderbook#2036
File: crates/js_api/src/filters/raindex_filter_store.rs:446-533
Timestamp: 2025-08-02T02:34:32.237Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore WASM tests (crates/js_api/src/filters/raindex_filter_store.rs), brusherru decided to focus on testing only methods without side effects (that don't use web_sys) due to difficulties with mocking localStorage and window APIs in the WASM test environment. This pragmatic approach tests pure logic separately from browser integration.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1913
File: Cargo.toml:55-55
Timestamp: 2025-06-06T16:38:04.182Z
Learning: In rain.orderbook repository, during PR chains involving dependency updates, wasm-bindgen-utils may temporarily point to git commits that don't contain the full required functionality, with the understanding that subsequent PRs in the chain will update it to the correct commit.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1744
File: crates/subgraph/src/orderbook_client.rs:44-46
Timestamp: 2025-05-14T05:13:59.713Z
Learning: In the rain.orderbook project, WASM dependencies are intentionally made available in non-WASM targets to facilitate testing of WASM-related functionality, so conditional compilation guards like `#[cfg(target_family = "wasm")]` should not be added to imports or implementations that may be needed for tests.
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: WASM bundle via nix develop -c rainix-wasm-artifacts
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1715
File: crates/js_api/src/common/mod.rs:111-118
Timestamp: 2025-04-30T09:28:36.960Z
Learning: In the rain.orderbook repository, the WASM tests are already properly configured with conditional compilation using `#[cfg(target_family = "wasm")]` and `#[cfg(not(target_family = "wasm"))]`, and don't require additional `wasm_bindgen_test_configure!(run_in_browser)` directives.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1710
File: crates/quote/Cargo.toml:30-30
Timestamp: 2025-05-14T04:49:14.621Z
Learning: In the rain.orderbook repository, wasm-bindgen-utils is intentionally used as an unconditional dependency because non-wasm targets (like tests) sometimes need to use it.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildCjs.js:38-53
Timestamp: 2025-10-25T21:06:38.487Z
Learning: In the rain.orderbook repository, build scripts in packages/orderbook/scripts/ (such as buildCjs.js and buildEsm.js) should keep duplicated logic separate rather than extracting to shared utilities, even when identical, to allow future divergence and to surface breaking changes as early failures.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildEsm.js:38-53
Timestamp: 2025-10-25T21:07:19.704Z
Learning: In the rain.orderbook repository, the deduplication logic in buildEsm.js (and similar build scripts) intentionally lacks defensive checks for indexOf returning -1. If duplicates are not found, the script should throw to surface breaking changes in wasm-bindgen output that require attention.
Learnt from: brusherru
PR: rainlanguage/rain.orderbook#2044
File: crates/common/src/raindex_client/vaults_list.rs:363-423
Timestamp: 2025-07-31T19:34:11.716Z
Learning: In the rainlanguage/rain.orderbook project, for WASM-exposed functionality like VaultsList, the team prefers to keep comprehensive tests in the non-WASM environment due to the complexity of recreating objects like RaindexVaults in WASM. WASM tests focus on basic functionality and error cases since the WASM code reuses the already-tested non-WASM implementation.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1715
File: crates/js_api/src/common/mod.rs:55-59
Timestamp: 2025-05-14T05:51:50.277Z
Learning: In the Rain Orderbook project, the error handling for WASM exported functions uses WasmEncodedError which includes both the original error message and a human-readable version, making direct modification of the JsValue conversion unnecessary.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1858
File: crates/subgraph/src/orderbook_client/mod.rs:54-58
Timestamp: 2025-05-19T13:40:56.080Z
Learning: The `wasm_bindgen_utils` crate in the Rain Orderbook project handles conditional compilation for `JsValue` and `JsError` internally, allowing `impl From<Error> for JsValue` to work on non-WASM targets without explicit cfg guards.
📚 Learning: 2025-05-14T05:13:59.713Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1744
File: crates/subgraph/src/orderbook_client.rs:44-46
Timestamp: 2025-05-14T05:13:59.713Z
Learning: In the rain.orderbook project, WASM dependencies are intentionally made available in non-WASM targets to facilitate testing of WASM-related functionality, so conditional compilation guards like `#[cfg(target_family = "wasm")]` should not be added to imports or implementations that may be needed for tests.

Applied to files:

  • Cargo.toml
  • flake.nix
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: Applies to crates/**/*.rs : Rust code lives in the workspace under crates/* (e.g., cli, common, bindings, js_api, quote, subgraph, settings, math, integration_tests)

Applied to files:

  • Cargo.toml
  • flake.nix
📚 Learning: 2025-04-30T09:28:36.960Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1715
File: crates/js_api/src/common/mod.rs:111-118
Timestamp: 2025-04-30T09:28:36.960Z
Learning: In the rain.orderbook repository, the WASM tests are already properly configured with conditional compilation using `#[cfg(target_family = "wasm")]` and `#[cfg(not(target_family = "wasm"))]`, and don't require additional `wasm_bindgen_test_configure!(run_in_browser)` directives.

Applied to files:

  • Cargo.toml
  • flake.nix
📚 Learning: 2025-05-14T04:49:14.621Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1710
File: crates/quote/Cargo.toml:30-30
Timestamp: 2025-05-14T04:49:14.621Z
Learning: In the rain.orderbook repository, wasm-bindgen-utils is intentionally used as an unconditional dependency because non-wasm targets (like tests) sometimes need to use it.

Applied to files:

  • Cargo.toml
  • flake.nix
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: WASM bundle via nix develop -c rainix-wasm-artifacts

Applied to files:

  • Cargo.toml
  • packages/orderbook/package.json
  • flake.nix
📚 Learning: 2025-05-19T13:40:56.080Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1858
File: crates/subgraph/src/orderbook_client/mod.rs:54-58
Timestamp: 2025-05-19T13:40:56.080Z
Learning: The `wasm_bindgen_utils` crate in the Rain Orderbook project handles conditional compilation for `JsValue` and `JsError` internally, allowing `impl From<Error> for JsValue` to work on non-WASM targets without explicit cfg guards.

Applied to files:

  • Cargo.toml
  • flake.nix
📚 Learning: 2025-07-31T19:34:11.716Z
Learnt from: brusherru
PR: rainlanguage/rain.orderbook#2044
File: crates/common/src/raindex_client/vaults_list.rs:363-423
Timestamp: 2025-07-31T19:34:11.716Z
Learning: In the rainlanguage/rain.orderbook project, for WASM-exposed functionality like VaultsList, the team prefers to keep comprehensive tests in the non-WASM environment due to the complexity of recreating objects like RaindexVaults in WASM. WASM tests focus on basic functionality and error cases since the WASM code reuses the already-tested non-WASM implementation.

Applied to files:

  • Cargo.toml
  • flake.nix
📚 Learning: 2025-08-02T02:34:32.237Z
Learnt from: brusherru
PR: rainlanguage/rain.orderbook#2036
File: crates/js_api/src/filters/raindex_filter_store.rs:446-533
Timestamp: 2025-08-02T02:34:32.237Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore WASM tests (crates/js_api/src/filters/raindex_filter_store.rs), brusherru decided to focus on testing only methods without side effects (that don't use web_sys) due to difficulties with mocking localStorage and window APIs in the WASM test environment. This pragmatic approach tests pure logic separately from browser integration.

Applied to files:

  • Cargo.toml
  • flake.nix
📚 Learning: 2025-06-06T16:38:04.182Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1913
File: Cargo.toml:55-55
Timestamp: 2025-06-06T16:38:04.182Z
Learning: In rain.orderbook repository, during PR chains involving dependency updates, wasm-bindgen-utils may temporarily point to git commits that don't contain the full required functionality, with the understanding that subsequent PRs in the chain will update it to the correct commit.

Applied to files:

  • Cargo.toml
  • packages/orderbook/package.json
  • flake.nix
📚 Learning: 2025-07-18T10:31:05.498Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2008
File: crates/common/src/raindex_client/add_orders.rs:85-86
Timestamp: 2025-07-18T10:31:05.498Z
Learning: In the rainlanguage/rain.orderbook codebase, cfg-guarded imports like `#[cfg(not(target_family = "wasm"))] use super::*;` in test modules are sometimes needed to fix compiler warnings, even when similar imports exist in nested sub-modules. These should not be removed as they serve a specific purpose in the compilation process.

Applied to files:

  • Cargo.toml
📚 Learning: 2025-10-25T21:06:38.487Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildCjs.js:38-53
Timestamp: 2025-10-25T21:06:38.487Z
Learning: In the rain.orderbook repository, build scripts in packages/orderbook/scripts/ (such as buildCjs.js and buildEsm.js) should keep duplicated logic separate rather than extracting to shared utilities, even when identical, to allow future divergence and to surface breaking changes as early failures.

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-07-01T21:26:42.195Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#1955
File: packages/orderbook/package.json:40-40
Timestamp: 2025-07-01T21:26:42.195Z
Learning: In the rain.orderbook project, the team does not require cross-platform compatibility improvements for the TypeScript check script in packages/orderbook/package.json. The current brace expansion syntax "./dist/**/*.{ts,js}" is sufficient for their development environment.

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-10-25T21:07:19.704Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildEsm.js:38-53
Timestamp: 2025-10-25T21:07:19.704Z
Learning: In the rain.orderbook repository, the deduplication logic in buildEsm.js (and similar build scripts) intentionally lacks defensive checks for indexOf returning -1. If duplicates are not found, the script should throw to surface breaking changes in wasm-bindgen output that require attention.

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-10-19T20:24:08.629Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/webapp/src/hooks.client.ts:2-2
Timestamp: 2025-10-19T20:24:08.629Z
Learning: In the rain.orderbook repository, the import `rainlanguage/orderbook/esm` in packages/webapp/src/hooks.client.ts is intentional and should not be changed to the root package path, as it's specific to the webapp build configuration.

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-10-06T08:05:02.438Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-06T08:05:02.438Z
Learning: Applies to packages/orderbook/**/*.{ts,tsx} : Orderbook TypeScript package must pass type/lint checks (npm run check -w rainlanguage/orderbook)

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-05-21T23:09:27.578Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T23:09:27.578Z
Learning: For PR #1884 in rainlanguage/rain.orderbook repository, I must always reassess the PR size after each new commit, calculating the total changes up to the very latest commit and ensuring accuracy of the report. The calculation must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and report in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number".

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-10-25T21:11:09.664Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/sizeCheck.js:1-11
Timestamp: 2025-10-25T21:11:09.664Z
Learning: In the rain.orderbook repository, build scripts like sizeCheck.js intentionally lack defensive error handling (e.g., checking for missing arguments or file existence). The scripts should fail with raw errors to surface configuration or build pipeline issues that require immediate attention.

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-10-06T08:05:02.438Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-06T08:05:02.438Z
Learning: Applies to packages/orderbook/**/*.{test,spec}.{ts,tsx} : Orderbook tests must pass (npm run test -w rainlanguage/orderbook)

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-05-21T21:26:31.566Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:26:31.566Z
Learning: For PR #1884 and future PRs in rainlanguage/rain.orderbook repository, provide PR size reports in a separate comment with ONLY the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number", without any additional text or explanation. Reports should exclude irrelevant files such as lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-10-06T08:05:02.438Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-06T08:05:02.438Z
Learning: Before pushing, re-run quick verification (lint-format-check:all, npm tests, cargo tests)

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: JS workspaces: nix develop -c npm run test/build commands at top-level

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: Quick preflight before PR: nix develop -c npm run lint-format-check:all && nix develop -c rainix-rs-static

Applied to files:

  • packages/orderbook/package.json
  • flake.nix
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: Tauri: nix develop .#tauri-shell --command cargo tauri dev

Applied to files:

  • packages/orderbook/package.json
  • flake.nix
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: Rust: build with nix develop -c cargo build --workspace; test with nix develop -c cargo test

Applied to files:

  • packages/orderbook/package.json
  • flake.nix
📚 Learning: 2025-10-06T08:05:02.438Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-06T08:05:02.438Z
Learning: Applies to packages/webapp/**/*.{test,spec}.{ts,tsx} : Webapp tests must pass (npm run test -w rainlanguage/webapp)

Applied to files:

  • packages/orderbook/package.json
📚 Learning: 2025-07-11T12:30:09.245Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1971
File: .github/workflows/vercel-docs-prod.yaml:32-34
Timestamp: 2025-07-11T12:30:09.245Z
Learning: findolor prefers not to pin Node versions explicitly in GitHub Actions workflows when using Nix with webapp-shell, considering the current setup sufficient for deterministic builds in the rainlanguage/rain.orderbook project.

Applied to files:

  • flake.nix
📚 Learning: 2025-05-21T21:25:47.873Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:25:47.873Z
Learning: After each new commit review for rainlanguage/rain.orderbook repository, generate a PR size report in a separate comment with the format: "TOTAL=number ADDITIONS=number DELETIONS=number". This report should exclude irrelevant files such as lock files (e.g., package-lock.json, cargo.lock).

Applied to files:

  • flake.nix
📚 Learning: 2025-05-21T21:24:53.708Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.

Applied to files:

  • flake.nix
🔇 Additional comments (3)
flake.nix (1)

245-245: LGTM! Targeted WASM build with size optimization.

The updated command correctly uses the new release-wasm profile and targets only the rain_orderbook_js_api package, which aligns with the PR's goal to reduce WASM artifact size. This is consistent with the corresponding build-wasm script in packages/orderbook/package.json.

Cargo.toml (1)

94-107: LGTM! Well-configured size-optimized WASM profile.

The release-wasm profile settings are appropriate for reducing WASM bundle size:

  • opt-level = "z" and lto = true maximize size reduction
  • strip = true, panic = "abort", and codegen-units = 1 further optimize for size
  • Disabled overflow and debug checks are standard for release builds

These settings align with the PR objective to reduce the WASM artifact to ~4.85 MB.

packages/orderbook/package.json (1)

34-35: LGTM! Clear multi-step build flow with optimized WASM compilation.

The updated build process follows a logical sequence:

  1. Clean directories
  2. Build WASM with the new release-wasm profile
  3. Generate TypeScript/JS bindings
  4. Validate with type checking

The build-wasm command is consistent with the flake.nix task and correctly targets the rain_orderbook_js_api package with size optimizations.


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

@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.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f31a040 and 72d5d13.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • package.json (1 hunks)
  • packages/orderbook/package.json (1 hunks)
  • packages/orderbook/scripts/build.js (2 hunks)
  • packages/orderbook/scripts/buildPackage.js (4 hunks)
  • packages/ui-components/package.json (1 hunks)
  • packages/webapp/package.json (1 hunks)
  • packages/webapp/src/hooks.client.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/orderbook/scripts/build.js
  • packages/ui-components/package.json
  • packages/webapp/package.json
  • packages/orderbook/package.json
  • packages/webapp/src/hooks.client.ts
  • packages/orderbook/scripts/buildPackage.js
packages/webapp/**/*.{svelte,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Webapp must pass Svelte lint/format checks (npm run svelte-lint-format-check -w @rainlanguage/webapp)

Files:

  • packages/webapp/src/hooks.client.ts
packages/{webapp,ui-components}/**/*.{svelte,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

If you modify frontend code, you must include a screenshot of the built webapp reflecting the change

Files:

  • packages/webapp/src/hooks.client.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: Applies to packages/** : JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)
📚 Learning: 2025-10-06T08:05:02.438Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-06T08:05:02.438Z
Learning: Applies to packages/webapp/**/*.{svelte,ts} : Webapp must pass Svelte lint/format checks (npm run svelte-lint-format-check -w rainlanguage/webapp)

Applied to files:

  • packages/webapp/package.json
🧬 Code graph analysis (2)
packages/orderbook/scripts/build.js (1)
packages/orderbook/scripts/buildPackage.js (2)
  • fs (1-1)
  • package (5-5)
packages/orderbook/scripts/buildPackage.js (1)
packages/orderbook/scripts/build.js (1)
  • buildType (4-4)
🪛 Biome (2.1.2)
packages/orderbook/scripts/build.js

[error] 27-27: Illegal use of reserved keyword package as an identifier in strict mode

(parse)

packages/orderbook/scripts/buildPackage.js

[error] 5-5: Illegal use of reserved keyword package as an identifier in strict mode

(parse)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: Deploy-Preview-Push
  • GitHub Check: Deploy-Docs-Preview
🔇 Additional comments (3)
packages/orderbook/package.json (1)

36-36: LGTM: build-webapp script aligns with new buildType flow.

This cleanly mirrors existing scripts and enables the webapp init path.

packages/webapp/package.json (1)

9-10: Frontend change: manual verification required for svelte lint/format checks and screenshot.

The sandbox environment lacks necessary dev dependencies (prettier/eslint) to verify the svelte checks. Manually verify that npm run svelte-lint-format-check -w @rainlanguage/webapp passes and ensure you've included a screenshot of the built webapp reflecting your changes, as required by repo guidelines.

package.json (1)

84-84: SvelteKit 2.47.1 upgrade: verify workspace compatibility in dev environment.

The sandbox cannot run full builds due to missing dependencies, but this upgrade requires manual verification. After dependencies are installed locally, ensure:

  • npm run svelte-lint-format-check -w @rainlanguage/webapp passes (required per project standards)
  • npm -w @rainlanguage/webapp run build succeeds (hooks typing changes in SvelteKit 2.x may impact webapp)
  • Other workspace builds complete without errors

Comment thread packages/orderbook/scripts/build.js Outdated
Comment thread packages/orderbook/scripts/buildPackage.js Outdated
Comment thread packages/ui-components/package.json Outdated
Comment thread packages/webapp/src/hooks.client.ts Outdated
@rouzwelt rouzwelt changed the title Fix web app issue for Safari browser Fix webapp issue for Safari browser Oct 19, 2025

@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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72d5d13 and 9dd6f80.

📒 Files selected for processing (1)
  • packages/webapp/src/hooks.client.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
packages/webapp/**/*.{svelte,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Webapp must pass Svelte lint/format checks (npm run svelte-lint-format-check -w @rainlanguage/webapp)

Files:

  • packages/webapp/src/hooks.client.ts
packages/{webapp,ui-components}/**/*.{svelte,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

If you modify frontend code, you must include a screenshot of the built webapp reflecting the change

Files:

  • packages/webapp/src/hooks.client.ts
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/webapp/src/hooks.client.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: Deploy-Docs-Preview
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Deploy-Preview-Push
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: git-clean
  • GitHub Check: test
🔇 Additional comments (2)
packages/webapp/src/hooks.client.ts (2)

12-18: LGTM! Client hooks are now correctly implemented.

The init hook is properly typed as ClientInit (fixing the previous ServerInit issue), and the handleError hook correctly implements error logging. The async initialization pattern appropriately handles WASM module setup before the app starts, addressing the Safari top-level await issue described in the PR.


1-18: Verify Svelte lint and format compliance locally.

The sandbox environment lacks necessary npm dependencies to run lint/format checks. You must verify compliance manually by running:

npm run svelte-lint-format-check -w @rainlanguage/webapp

from your local environment before pushing.

Comment thread packages/webapp/src/hooks.client.ts Outdated
@rainlanguage rainlanguage deleted a comment from coderabbitai Bot Oct 19, 2025
@rainlanguage rainlanguage deleted a comment from coderabbitai Bot Oct 19, 2025

@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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
packages/orderbook/scripts/buildPackage.js (3)

21-34: Avoid unnecessary Buffer copy; use toString('base64').

Buffer.from(buf, 'binary') creates a redundant copy. Convert the existing Buffer directly.

-const wasmCjsBytes = fs.readFileSync(`./temp/node/${pkg}/${pkg}_bg.wasm`);
+const wasmCjsBytes = fs.readFileSync(`./temp/node/${pkg}/${pkg}_bg.wasm`);
 fs.writeFileSync(
   `./dist/cjs/orderbook_wbg.json`,
   JSON.stringify({
-    wasm: Buffer.from(wasmCjsBytes, 'binary').toString('base64')
+    wasm: wasmCjsBytes.toString('base64')
   })
 );
-const wasmEsmBytes = fs.readFileSync(`./temp/web/${pkg}/${pkg}_bg.wasm`);
+const wasmEsmBytes = fs.readFileSync(`./temp/web/${pkg}/${pkg}_bg.wasm`);
 fs.writeFileSync(
   `./dist/esm/orderbook_wbg.json`,
   JSON.stringify({
-    wasm: Buffer.from(wasmEsmBytes, 'binary').toString('base64')
+    wasm: wasmEsmBytes.toString('base64')
   })
 );

53-66: Fix CJS JSON path; consider buffer/ polyfill.

From dist/cjs/index.js, the JSON is alongside it, so require ./orderbook_wbg.json. Using buffer/ improves browser bundler compatibility. Based on learnings.

-cjs = cjs.replace(
-	`const path = require('path').join(__dirname, '${pkg}_bg.wasm');
-const bytes = require('fs').readFileSync(path);`,
-	`
-const { Buffer } = require('buffer');
-const wasmB64 = require('../cjs/orderbook_wbg.json');
-const bytes = Buffer.from(wasmB64.wasm, 'base64');`
-);
+cjs = cjs.replace(
+  `const path = require('path').join(__dirname, '${pkg}_bg.wasm');
+const bytes = require('fs').readFileSync(path);`,
+  `
+const { Buffer } = require('buffer/'); // npm polyfill for bundlers
+const wasmB64 = require('./orderbook_wbg.json');
+const bytes = Buffer.from(wasmB64.wasm, 'base64');`
+);

36-51: Consider making dist dir creation idempotent here too.

If buildPackage.js runs standalone, ensure dist/{cjs,esm} exist.

+fs.mkdirSync('./dist/cjs', { recursive: true });
+fs.mkdirSync('./dist/esm', { recursive: true });

Also applies to: 109-110

♻️ Duplicate comments (2)
packages/orderbook/scripts/buildPackage.js (2)

5-5: Good: reserved identifier fixed (pkg).


72-81: ESM: fix JSON path, add import assertion, prefer buffer/.

index.js sits in dist/esm/; use ./orderbook_wbg.json. Add assert { type: 'json' } for Node ESM; use buffer/. Based on learnings.

-  `import { Buffer } from 'buffer';
-import wasmB64 from '../esm/orderbook_wbg.json';
+  `import { Buffer } from 'buffer/';
+import wasmB64 from './orderbook_wbg.json' assert { type: 'json' };
 const bytes = Buffer.from(wasmB64.wasm, 'base64');
 initSync(bytes);`
-  `import { Buffer } from 'buffer';
-import wasmB64 from '../esm/orderbook_wbg.json';
+  `import { Buffer } from 'buffer/';
+import wasmB64 from './orderbook_wbg.json' assert { type: 'json' };
 const bytes = Buffer.from(wasmB64.wasm, 'base64');\n
 /** Initialize the Orderbook pkg WebAssembly module */
 export async function init() {
   await __wbg_init(bytes);
 }`
-  `import { Buffer } from 'buffer';
-import wasmB64 from '../esm/orderbook_wbg.json';
+  `import { Buffer } from 'buffer/';
+import wasmB64 from './orderbook_wbg.json' assert { type: 'json' };
 const bytes = Buffer.from(wasmB64.wasm, 'base64');
 await __wbg_init(bytes);`

Also applies to: 88-97, 100-108

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eabe916 and 99c3c4d.

📒 Files selected for processing (2)
  • packages/orderbook/scripts/build.js (2 hunks)
  • packages/orderbook/scripts/buildPackage.js (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/orderbook/scripts/build.js
  • packages/orderbook/scripts/buildPackage.js
🧬 Code graph analysis (2)
packages/orderbook/scripts/build.js (1)
packages/orderbook/scripts/buildPackage.js (2)
  • fs (1-1)
  • pkg (5-5)
packages/orderbook/scripts/buildPackage.js (1)
packages/orderbook/scripts/build.js (2)
  • buildType (4-4)
  • fs (1-1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: Deploy-Docs-Preview
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Deploy-Preview-Push
🔇 Additional comments (3)
packages/orderbook/scripts/buildPackage.js (2)

47-50: Verification confirms code is correct—no action required.

The webapp already imports the named export correctly: import { init as initOrderbookPackage } from '@rainlanguage/orderbook/esm' in packages/webapp/src/hooks.client.ts. The buildPackage.js typings logic (ESM includes init(), CJS omits it) aligns with the actual import pattern used.


60-63: Clarify Vite JSON handling approach or document tested configuration.

The review comment raises a valid portability concern, but lacks specificity. The generated JSON imports (lines 60-63, 77-81, 91-96, 103-106) work with the current Vite setup in both webapp and ui-components. The generated code uses bare JSON imports without assertions (CommonJS require() and ESM import), which modern Vite handles automatically.

The comment suggests either testing or adding assertions, but doesn't clarify which approach is preferred. Since dist/ is a build artifact and the current Vite configs work without explicit JSON handling, either:

  1. Document that the codebase requires Vite ≥5.0 (or your current tested version) for JSON import support, or
  2. Add import assertions to the generated code for explicit Node ESM compatibility if targeting broader runtime environments.
packages/orderbook/scripts/build.js (1)

11-13: Concern verified; index.d.ts files are properly generated by buildPackage.js.

Verification confirms that buildPackage.js explicitly generates both dist/cjs/index.d.ts (line 46) and dist/esm/index.d.ts (line 50). The build pipeline includes a TypeScript validation step that ensures these files exist and are valid before publishing. The re-export files in lines 11-13 depend on these generated files, which are created during the buildPackage phase. No action required.

Comment thread packages/orderbook/scripts/build.js Outdated
Comment thread packages/orderbook/scripts/build.js Outdated
Comment thread packages/orderbook/scripts/buildPackage.js Outdated
@rouzwelt
rouzwelt requested a review from hardyjosh October 19, 2025 20:33

@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.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99c3c4d and 9cbed8b.

📒 Files selected for processing (2)
  • packages/ui-components/src/lib/components/ListViewOrderbookFilters.svelte (1 hunks)
  • packages/webapp/src/hooks.client.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
packages/ui-components/**/*.{svelte,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

UI components must pass Svelte lint/format checks (npm run svelte-lint-format-check -w @rainlanguage/ui-components)

Files:

  • packages/ui-components/src/lib/components/ListViewOrderbookFilters.svelte
packages/{webapp,ui-components}/**/*.{svelte,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

If you modify frontend code, you must include a screenshot of the built webapp reflecting the change

Files:

  • packages/ui-components/src/lib/components/ListViewOrderbookFilters.svelte
  • packages/webapp/src/hooks.client.ts
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/ui-components/src/lib/components/ListViewOrderbookFilters.svelte
  • packages/webapp/src/hooks.client.ts
packages/webapp/**/*.{svelte,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Webapp must pass Svelte lint/format checks (npm run svelte-lint-format-check -w @rainlanguage/webapp)

Files:

  • packages/webapp/src/hooks.client.ts
🧠 Learnings (1)
📚 Learning: 2025-10-19T20:24:08.611Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/webapp/src/hooks.client.ts:2-2
Timestamp: 2025-10-19T20:24:08.611Z
Learning: In the rain.orderbook repository, the import `rainlanguage/orderbook/esm` in packages/webapp/src/hooks.client.ts is intentional and should not be changed to the root package path, as it's specific to the webapp build configuration.

Applied to files:

  • packages/webapp/src/hooks.client.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: Deploy-Preview-Push
  • GitHub Check: Deploy-Docs-Preview
🔇 Additional comments (3)
packages/webapp/src/hooks.client.ts (3)

1-2: LGTM! Import types and paths are correct.

The imports use the correct client-side types (ClientInit and HandleClientError) for hooks.client.ts, and the /esm import path is intentional for the webapp-specific build configuration.

Based on learnings


15-17: LGTM! Error handler implementation is appropriate.

The error handler correctly logs client-side errors with context. This is sufficient for the Safari fix objective.


1-17: Verify webapp lint/format checks pass locally before merge.

The code is correctly structured with valid TypeScript syntax and proper import paths. The @rainlanguage/orderbook/esm import correctly references the entry point generated by the orderbook build script (esm.js). However, npm-based lint/format verification could not be completed in the sandbox environment due to missing dependencies. Ensure npm run svelte-lint-format-check -w @rainlanguage/webapp passes locally before merging.

Comment thread packages/ui-components/src/lib/components/ListViewOrderbookFilters.svelte Outdated
Comment thread packages/webapp/src/hooks.client.ts Outdated

@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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cbed8b and 77960b9.

📒 Files selected for processing (1)
  • packages/webapp/src/hooks.client.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
packages/webapp/**/*.{svelte,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Webapp must pass Svelte lint/format checks (npm run svelte-lint-format-check -w @rainlanguage/webapp)

Files:

  • packages/webapp/src/hooks.client.ts
packages/{webapp,ui-components}/**/*.{svelte,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

If you modify frontend code, you must include a screenshot of the built webapp reflecting the change

Files:

  • packages/webapp/src/hooks.client.ts
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/webapp/src/hooks.client.ts
🧠 Learnings (1)
📚 Learning: 2025-10-19T20:24:08.611Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/webapp/src/hooks.client.ts:2-2
Timestamp: 2025-10-19T20:24:08.611Z
Learning: In the rain.orderbook repository, the import `rainlanguage/orderbook/esm` in packages/webapp/src/hooks.client.ts is intentional and should not be changed to the root package path, as it's specific to the webapp build configuration.

Applied to files:

  • packages/webapp/src/hooks.client.ts
🔇 Additional comments (2)
packages/webapp/src/hooks.client.ts (2)

1-2: Imports are correct; past concerns resolved.

The ClientInit type is correctly used (addressing the ServerInit issue from past reviews), and HandleClientError is properly imported and used on line 15. The /esm subpath import is intentional and webapp-specific.

Based on learnings


11-13: Init hook correctly addresses the Safari issue.

The ClientInit hook properly initializes the WASM module before the webapp starts, working around Safari's top-level await bug. The implementation is clean and matches the PR objectives.

Comment thread packages/webapp/src/hooks.client.ts Outdated
@rouzwelt
rouzwelt marked this pull request as draft October 23, 2025 16:12

@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.

Actionable comments posted: 4

♻️ Duplicate comments (2)
packages/orderbook/scripts/buildPackage.js (1)

23-36: Fix CJS JSON import path and remove unnecessary Buffer wrapper.

The CJS wrapper at line 63 references '../cjs/orderbook_wbg.json', which will resolve incorrectly. Since the generated wrapper lives at ./dist/cjs/${pkg}/index.js and the JSON at ./dist/cjs/${pkg}/orderbook_wbg.json, the path should be './orderbook_wbg.json'. Additionally, wasmCjsBytes and wasmEsmBytes are already Buffers; wrapping them with Buffer.from(..., 'binary') is redundant.

Apply this diff:

 const wasmCjsBytes = fs.readFileSync(`./temp/node/${pkg}/${pkg}_bg.wasm`);
 fs.writeFileSync(
 	`./dist/cjs/${pkg}/orderbook_wbg.json`,
 	JSON.stringify({
-		wasm: Buffer.from(wasmCjsBytes, 'binary').toString('base64')
+		wasm: wasmCjsBytes.toString('base64')
 	})
 );
 const wasmEsmBytes = fs.readFileSync(`./temp/web/${pkg}/${pkg}_bg.wasm`);
 fs.writeFileSync(
 	`./dist/esm/${pkg}/orderbook_wbg.json`,
 	JSON.stringify({
-		wasm: Buffer.from(wasmEsmBytes, 'binary').toString('base64')
+		wasm: wasmEsmBytes.toString('base64')
 	})
 );

And fix the CJS JSON path on line 63:

-const wasmB64 = require('../cjs/orderbook_wbg.json');
+const wasmB64 = require('./orderbook_wbg.json');

Based on past review comments.

packages/orderbook/scripts/build.js (1)

4-4: Document accepted buildType values.

Consider adding a comment documenting the accepted buildType values: '' (default/node), 'webapp', and 'tauri'.

Example:

+// buildType: '' (default), 'webapp', or 'tauri'
 const [buildType = ''] = process.argv.slice(2);

Based on past review comments.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36a5dee and 68ea21e.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • Cargo.toml (1 hunks)
  • crates/wasm_wrapper/Cargo.toml (1 hunks)
  • crates/wasm_wrapper/src/lib.rs (1 hunks)
  • flake.nix (2 hunks)
  • packages/orderbook/scripts/build.js (1 hunks)
  • packages/orderbook/scripts/buildPackage.js (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/orderbook/scripts/build.js
  • packages/orderbook/scripts/buildPackage.js
crates/*/{src,tests,benches,examples}/**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Rust code must pass clippy with all warnings denied (cargo clippy --workspace --all-targets --all-features -D warnings)

Files:

  • crates/wasm_wrapper/src/lib.rs
crates/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Rust code lives in the workspace under crates/* (e.g., cli, common, bindings, js_api, quote, subgraph, settings, math, integration_tests)

Files:

  • crates/wasm_wrapper/src/lib.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Format Rust with nix develop -c cargo fmt --all
Lint Rust with nix develop -c rainix-rs-static (preconfigured flags)
Use snake_case for Rust crates/modules and PascalCase for types

Files:

  • crates/wasm_wrapper/src/lib.rs
🧠 Learnings (9)
📚 Learning: 2025-07-01T21:26:42.195Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#1955
File: packages/orderbook/package.json:40-40
Timestamp: 2025-07-01T21:26:42.195Z
Learning: In the rain.orderbook project, the team does not require cross-platform compatibility improvements for the TypeScript check script in packages/orderbook/package.json. The current brace expansion syntax "./dist/**/*.{ts,js}" is sufficient for their development environment.

Applied to files:

  • packages/orderbook/scripts/build.js
📚 Learning: 2025-05-14T04:49:14.621Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1710
File: crates/quote/Cargo.toml:30-30
Timestamp: 2025-05-14T04:49:14.621Z
Learning: In the rain.orderbook repository, wasm-bindgen-utils is intentionally used as an unconditional dependency because non-wasm targets (like tests) sometimes need to use it.

Applied to files:

  • Cargo.toml
  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-05-14T05:13:59.713Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1744
File: crates/subgraph/src/orderbook_client.rs:44-46
Timestamp: 2025-05-14T05:13:59.713Z
Learning: In the rain.orderbook project, WASM dependencies are intentionally made available in non-WASM targets to facilitate testing of WASM-related functionality, so conditional compilation guards like `#[cfg(target_family = "wasm")]` should not be added to imports or implementations that may be needed for tests.

Applied to files:

  • Cargo.toml
  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-06-06T16:38:04.182Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1913
File: Cargo.toml:55-55
Timestamp: 2025-06-06T16:38:04.182Z
Learning: In rain.orderbook repository, during PR chains involving dependency updates, wasm-bindgen-utils may temporarily point to git commits that don't contain the full required functionality, with the understanding that subsequent PRs in the chain will update it to the correct commit.

Applied to files:

  • Cargo.toml
  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: Applies to crates/**/*.rs : Rust code lives in the workspace under crates/* (e.g., cli, common, bindings, js_api, quote, subgraph, settings, math, integration_tests)

Applied to files:

  • Cargo.toml
  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-04-30T09:28:36.960Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1715
File: crates/js_api/src/common/mod.rs:111-118
Timestamp: 2025-04-30T09:28:36.960Z
Learning: In the rain.orderbook repository, the WASM tests are already properly configured with conditional compilation using `#[cfg(target_family = "wasm")]` and `#[cfg(not(target_family = "wasm"))]`, and don't require additional `wasm_bindgen_test_configure!(run_in_browser)` directives.

Applied to files:

  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-05-19T13:40:56.080Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1858
File: crates/subgraph/src/orderbook_client/mod.rs:54-58
Timestamp: 2025-05-19T13:40:56.080Z
Learning: The `wasm_bindgen_utils` crate in the Rain Orderbook project handles conditional compilation for `JsValue` and `JsError` internally, allowing `impl From<Error> for JsValue` to work on non-WASM targets without explicit cfg guards.

Applied to files:

  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: WASM bundle via nix develop -c rainix-wasm-artifacts

Applied to files:

  • flake.nix
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: Rust: build with nix develop -c cargo build --workspace; test with nix develop -c cargo test

Applied to files:

  • flake.nix
🧬 Code graph analysis (2)
packages/orderbook/scripts/build.js (1)
packages/orderbook/scripts/buildPackage.js (2)
  • fs (1-1)
  • pkg (5-5)
packages/orderbook/scripts/buildPackage.js (1)
packages/orderbook/scripts/build.js (1)
  • buildType (4-4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: Deploy-Preview-Push
  • GitHub Check: Deploy-Docs-Preview
🔇 Additional comments (8)
packages/orderbook/scripts/buildPackage.js (2)

8-9: LGTM — Per-package distribution directories.

The per-package directory structure aligns with the new multi-package build flow.


49-52: LGTM — Webapp-specific TypeScript declarations.

The conditional export of the init() function for webapp builds aligns with the Safari fix objective.

packages/orderbook/scripts/build.js (3)

18-19: LGTM — Multi-package ESM exports.

The new index files correctly aggregate exports from both wasm_async_compile_wrapper and js_api packages, supporting the new per-package build structure.


36-36: Commented check step — intentional or leftover?

The npm run check step is commented out. If this is temporary for debugging, consider re-enabling it or adding a TODO comment explaining why it's disabled.

Is the check step intentionally disabled, or should it be re-enabled before merge?


27-30: Review wasm_async_compile_wrapper webapp mode handling for completeness.

The build script correctly integrates wasm_async_compile_wrapper alongside js_api. Both Rust crates are properly configured as WASM libraries:

  • rain_orderbook_js_api (crates/js_api/Cargo.toml)
  • rain_orderbook_wasm_async_compile_wrapper (crates/wasm_wrapper/Cargo.toml)

The package names are consistent throughout the build pipeline. However, there's an asymmetry in webapp mode: buildPackage.js (lines 59-78) exports an async init_wasm() function for js_api but performs only synchronous initialization for wasm_async_compile_wrapper without exporting a function. Verify this difference is intentional and that consumers of wasm_async_compile_wrapper don't require an exported async init in webapp builds.

Cargo.toml (1)

94-95: LGTM — Workspace dependency for new wasm wrapper crate.

The workspace dependency declaration correctly integrates the new rain_orderbook_wasm_async_compile_wrapper crate at crates/wasm_wrapper.

crates/wasm_wrapper/src/lib.rs (1)

14-18: Async start function triggers init on module load.

The #[wasm_bindgen(start)] attribute ensures compile_wasm_async runs automatically when the WASM module loads, calling into JS init_wasm(). This aligns with the PR objective to remove top-level await and provide explicit initialization. Confirm that this start function is compatible with the webapp ClientInit hook invocation pattern.

Verify that the webapp ClientInit hook correctly loads and awaits this module's initialization.

crates/wasm_wrapper/Cargo.toml (1)

1-15: LGTM — Correctly configured WASM cdylib crate.

The manifest properly declares a cdylib for WASM output with workspace-inherited metadata. The dependencies on futures and wasm-bindgen-utils are appropriate for async WASM initialization. Per learnings, wasm-bindgen-utils is intentionally unconditional to support testing.

Based on learnings.

Comment thread crates/wasm_wrapper/src/lib.rs Outdated
Comment thread flake.nix Outdated
Comment thread packages/orderbook/scripts/buildPackage.js Outdated
Comment thread packages/orderbook/scripts/buildPackage.js Outdated
@rouzwelt
rouzwelt marked this pull request as ready for review October 24, 2025 16:16

@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.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68ea21e and 543bde6.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • tauri-app/src-tauri/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • crates/wasm_wrapper/Cargo.toml (1 hunks)
  • crates/wasm_wrapper/src/lib.rs (1 hunks)
  • packages/orderbook/package.json (1 hunks)
  • packages/orderbook/scripts/build.js (1 hunks)
  • packages/orderbook/scripts/buildCjs.js (1 hunks)
  • packages/orderbook/scripts/buildEsm.js (1 hunks)
  • packages/orderbook/scripts/buildPackage.js (0 hunks)
  • packages/webapp/package.json (1 hunks)
  • tauri-app/package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/orderbook/scripts/buildPackage.js
🧰 Additional context used
📓 Path-based instructions (5)
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/webapp/package.json
  • packages/orderbook/package.json
  • packages/orderbook/scripts/buildEsm.js
  • packages/orderbook/scripts/build.js
  • packages/orderbook/scripts/buildCjs.js
crates/*/{src,tests,benches,examples}/**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Rust code must pass clippy with all warnings denied (cargo clippy --workspace --all-targets --all-features -D warnings)

Files:

  • crates/wasm_wrapper/src/lib.rs
crates/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Rust code lives in the workspace under crates/* (e.g., cli, common, bindings, js_api, quote, subgraph, settings, math, integration_tests)

Files:

  • crates/wasm_wrapper/src/lib.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Format Rust with nix develop -c cargo fmt --all
Lint Rust with nix develop -c rainix-rs-static (preconfigured flags)
Use snake_case for Rust crates/modules and PascalCase for types

Files:

  • crates/wasm_wrapper/src/lib.rs
tauri-app/**

📄 CodeRabbit inference engine (AGENTS.md)

Desktop app code is in tauri-app (Rust + Svelte); src-tauri is not part of the Cargo workspace

Files:

  • tauri-app/package.json
🧠 Learnings (6)
📚 Learning: 2025-05-14T04:49:14.621Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1710
File: crates/quote/Cargo.toml:30-30
Timestamp: 2025-05-14T04:49:14.621Z
Learning: In the rain.orderbook repository, wasm-bindgen-utils is intentionally used as an unconditional dependency because non-wasm targets (like tests) sometimes need to use it.

Applied to files:

  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-05-14T05:13:59.713Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1744
File: crates/subgraph/src/orderbook_client.rs:44-46
Timestamp: 2025-05-14T05:13:59.713Z
Learning: In the rain.orderbook project, WASM dependencies are intentionally made available in non-WASM targets to facilitate testing of WASM-related functionality, so conditional compilation guards like `#[cfg(target_family = "wasm")]` should not be added to imports or implementations that may be needed for tests.

Applied to files:

  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-04-30T09:28:36.960Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1715
File: crates/js_api/src/common/mod.rs:111-118
Timestamp: 2025-04-30T09:28:36.960Z
Learning: In the rain.orderbook repository, the WASM tests are already properly configured with conditional compilation using `#[cfg(target_family = "wasm")]` and `#[cfg(not(target_family = "wasm"))]`, and don't require additional `wasm_bindgen_test_configure!(run_in_browser)` directives.

Applied to files:

  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-05-19T13:40:56.080Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1858
File: crates/subgraph/src/orderbook_client/mod.rs:54-58
Timestamp: 2025-05-19T13:40:56.080Z
Learning: The `wasm_bindgen_utils` crate in the Rain Orderbook project handles conditional compilation for `JsValue` and `JsError` internally, allowing `impl From<Error> for JsValue` to work on non-WASM targets without explicit cfg guards.

Applied to files:

  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-06-06T16:38:04.182Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1913
File: Cargo.toml:55-55
Timestamp: 2025-06-06T16:38:04.182Z
Learning: In rain.orderbook repository, during PR chains involving dependency updates, wasm-bindgen-utils may temporarily point to git commits that don't contain the full required functionality, with the understanding that subsequent PRs in the chain will update it to the correct commit.

Applied to files:

  • crates/wasm_wrapper/Cargo.toml
📚 Learning: 2025-07-01T21:26:42.195Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#1955
File: packages/orderbook/package.json:40-40
Timestamp: 2025-07-01T21:26:42.195Z
Learning: In the rain.orderbook project, the team does not require cross-platform compatibility improvements for the TypeScript check script in packages/orderbook/package.json. The current brace expansion syntax "./dist/**/*.{ts,js}" is sufficient for their development environment.

Applied to files:

  • crates/wasm_wrapper/src/lib.rs
  • packages/orderbook/scripts/build.js
🧬 Code graph analysis (3)
packages/orderbook/scripts/buildEsm.js (1)
packages/orderbook/scripts/buildCjs.js (5)
  • fs (1-1)
  • require (2-2)
  • packagePrefix (4-4)
  • pkg (5-5)
  • dts (29-31)
packages/orderbook/scripts/build.js (2)
packages/orderbook/scripts/buildEsm.js (2)
  • fs (1-1)
  • pkg (5-5)
packages/orderbook/scripts/buildCjs.js (2)
  • fs (1-1)
  • pkg (5-5)
packages/orderbook/scripts/buildCjs.js (1)
packages/orderbook/scripts/buildEsm.js (5)
  • fs (1-1)
  • require (2-2)
  • packagePrefix (4-4)
  • pkg (5-5)
  • dts (26-28)
🪛 Biome (2.1.2)
packages/orderbook/scripts/buildCjs.js

[error] 8-8: Illegal return statement outside of a function

(parse)

Comment thread packages/orderbook/scripts/buildCjs.js Outdated
const [pkg] = process.argv.slice(2);

// for cjs we only need to build "js_api" since we dont have limitations on wasm init
if (pkg !== "js_api") return;

@coderabbitai coderabbitai Bot Oct 24, 2025

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.

⚠️ Potential issue | 🔴 Critical

Remove the top-level return to prevent a SyntaxError.

return at the module top level throws “SyntaxError: Illegal return statement”, so the CJS build script aborts before doing anything. Please replace it with an early exit that Node accepts (for example, process.exit(0) or wrap the logic in a function).

-// for cjs we only need to build "js_api" since we dont have limitations on wasm init
-if (pkg !== "js_api") return;
+// for cjs we only need to build "js_api" since we dont have limitations on wasm init
+if (pkg !== "js_api") {
+    process.exit(0);
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (pkg !== "js_api") return;
// for cjs we only need to build "js_api" since we dont have limitations on wasm init
if (pkg !== "js_api") {
process.exit(0);
}
🧰 Tools
🪛 Biome (2.1.2)

[error] 8-8: Illegal return statement outside of a function

(parse)

🤖 Prompt for AI Agents
In packages/orderbook/scripts/buildCjs.js around line 8, the top-level "return"
causes a "SyntaxError: Illegal return statement" in Node; replace it with a
Node-friendly early exit (e.g., call process.exit(0)) or wrap the script body in
a function and invoke it so you can use return inside that function; update the
file to use one of these approaches so the script exits early without a
top-level return.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not needed, its ok

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.

@rouzwelt Understood! You're right—in a CommonJS script like this one (using require), the top-level return works fine because Node.js wraps the module code in a function. The early exit pattern is valid here. I'll leave it as-is.

Comment thread packages/orderbook/scripts/buildEsm.js Outdated
Comment on lines +57 to +69
esm = esm.replace(`export { initSync };
export default __wbg_init;`,
`import { Buffer } from 'buffer';
import wasmB64 from './orderbook_wbg.json';
const bytes = Buffer.from(wasmB64.wasm, 'base64');\n
/** Initializes this package WebAssembly module */
export async function init_wasm() {
try {
initSync(bytes);
} catch (error) {
await __wbg_init(bytes);
}
}`

@coderabbitai coderabbitai Bot Oct 24, 2025

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.

⚠️ Potential issue | 🔴 Critical

Restore the default init export (and initSync re-export) to avoid breaking consumers.

Replacing the generated footer removes both export { initSync }; and the default export, so existing code that does import init from '@rainlanguage/orderbook/js_api' now receives undefined, while our .d.ts still advertises the default export. Please re-expose the same surface by keeping initSync and defaulting to the new init_wasm, and update the .d.ts augmentation to match.

 if (pkg === 'wasm_async_compile_wrapper') {
   esm = esm.replace(`export { initSync };
 export default __wbg_init;`,
     `import { Buffer } from 'buffer';
 import wasmB64 from './orderbook_wbg.json';
 const bytes = Buffer.from(wasmB64.wasm, 'base64');\n
 initSync(bytes);`
     );
 } else {
   esm = esm.replace(`export { initSync };
 export default __wbg_init;`,
     `import { Buffer } from 'buffer';
 import wasmB64 from './orderbook_wbg.json';
 const bytes = Buffer.from(wasmB64.wasm, 'base64');\n
+export { initSync };
 /** Initializes this package WebAssembly module */
 export async function init_wasm() {
     try {
         initSync(bytes);
     } catch (error) {
         await __wbg_init(bytes);   
     }
 }
+export default init_wasm;`
     );
 }

Update the DTS addition accordingly:

 if (pkg !== 'wasm_async_compile_wrapper') {
-    dts += "/** Initializes this package WebAssembly module */\nexport function init_wasm(): Promise<void>\n";
+    dts += "/** Initializes this package WebAssembly module */\nexport function init_wasm(): Promise<void>;\nexport default init_wasm;\n";
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/orderbook/scripts/buildEsm.js around lines 57 to 69, the replacement
footer removed the generated `export { initSync };` and the default export,
breaking consumers; restore the public surface by re-exporting `initSync` and
making the default export point to the new `init_wasm` (i.e., keep `export {
initSync };` and add `export default init_wasm;` while leaving the `init_wasm`
implementation intact), and update the package's .d.ts augmentation so the
default export type matches `init_wasm` (and still declares `export { initSync
};`) to keep runtime and type definitions consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not needed

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.

@rouzwelt, understood. I'll note your decision to keep the current implementation as-is.

@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.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 543bde6 and 3d9fdd4.

📒 Files selected for processing (7)
  • Cargo.toml (1 hunks)
  • flake.nix (1 hunks)
  • packages/orderbook/package.json (1 hunks)
  • packages/orderbook/scripts/build.js (2 hunks)
  • packages/orderbook/scripts/buildCjs.js (1 hunks)
  • packages/orderbook/scripts/buildEsm.js (1 hunks)
  • packages/orderbook/scripts/sizeCheck.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/orderbook/scripts/buildCjs.js
  • packages/orderbook/scripts/build.js
  • packages/orderbook/scripts/sizeCheck.js
  • packages/orderbook/package.json
  • packages/orderbook/scripts/buildEsm.js
🧠 Learnings (6)
📚 Learning: 2025-07-01T21:26:42.195Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#1955
File: packages/orderbook/package.json:40-40
Timestamp: 2025-07-01T21:26:42.195Z
Learning: In the rain.orderbook project, the team does not require cross-platform compatibility improvements for the TypeScript check script in packages/orderbook/package.json. The current brace expansion syntax "./dist/**/*.{ts,js}" is sufficient for their development environment.

Applied to files:

  • packages/orderbook/scripts/build.js
📚 Learning: 2025-05-14T05:13:59.713Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1744
File: crates/subgraph/src/orderbook_client.rs:44-46
Timestamp: 2025-05-14T05:13:59.713Z
Learning: In the rain.orderbook project, WASM dependencies are intentionally made available in non-WASM targets to facilitate testing of WASM-related functionality, so conditional compilation guards like `#[cfg(target_family = "wasm")]` should not be added to imports or implementations that may be needed for tests.

Applied to files:

  • Cargo.toml
  • flake.nix
📚 Learning: 2025-04-30T09:28:36.960Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1715
File: crates/js_api/src/common/mod.rs:111-118
Timestamp: 2025-04-30T09:28:36.960Z
Learning: In the rain.orderbook repository, the WASM tests are already properly configured with conditional compilation using `#[cfg(target_family = "wasm")]` and `#[cfg(not(target_family = "wasm"))]`, and don't require additional `wasm_bindgen_test_configure!(run_in_browser)` directives.

Applied to files:

  • Cargo.toml
  • flake.nix
📚 Learning: 2025-05-14T04:49:14.621Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1710
File: crates/quote/Cargo.toml:30-30
Timestamp: 2025-05-14T04:49:14.621Z
Learning: In the rain.orderbook repository, wasm-bindgen-utils is intentionally used as an unconditional dependency because non-wasm targets (like tests) sometimes need to use it.

Applied to files:

  • Cargo.toml
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: WASM bundle via nix develop -c rainix-wasm-artifacts

Applied to files:

  • flake.nix
📚 Learning: 2025-10-06T08:05:50.452Z
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: Rust: build with nix develop -c cargo build --workspace; test with nix develop -c cargo test

Applied to files:

  • flake.nix
🧬 Code graph analysis (4)
packages/orderbook/scripts/buildCjs.js (1)
packages/orderbook/scripts/buildEsm.js (7)
  • fs (1-1)
  • pkg (5-5)
  • dts (26-28)
  • dups (38-45)
  • index (47-47)
  • start (49-49)
  • end (50-50)
packages/orderbook/scripts/build.js (3)
packages/orderbook/scripts/buildCjs.js (2)
  • fs (1-1)
  • pkg (5-5)
packages/orderbook/scripts/buildEsm.js (2)
  • fs (1-1)
  • pkg (5-5)
packages/orderbook/scripts/sizeCheck.js (2)
  • fs (1-1)
  • pkg (5-5)
packages/orderbook/scripts/sizeCheck.js (3)
packages/orderbook/scripts/build.js (2)
  • fs (1-1)
  • require (2-2)
packages/orderbook/scripts/buildCjs.js (3)
  • fs (1-1)
  • require (2-2)
  • pkg (5-5)
packages/orderbook/scripts/buildEsm.js (4)
  • fs (1-1)
  • require (2-2)
  • pkg (5-5)
  • wasmEsmBytes (17-17)
packages/orderbook/scripts/buildEsm.js (2)
packages/orderbook/scripts/buildCjs.js (7)
  • fs (1-1)
  • pkg (5-5)
  • dts (26-28)
  • dups (38-45)
  • index (47-47)
  • start (49-49)
  • end (50-50)
packages/orderbook/scripts/sizeCheck.js (3)
  • fs (1-1)
  • pkg (5-5)
  • wasmEsmBytes (8-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Deploy-Preview-Push
  • GitHub Check: Deploy-Docs-Preview
🔇 Additional comments (11)
flake.nix (1)

243-243: LGTM! Build command correctly targets the js_api package with the new profile.

The change from workspace-wide build with exclusions to a focused single-package build using the release-wasm profile aligns with the per-package build strategy introduced across the PR.

Cargo.toml (1)

94-107: Verify that disabling overflow checks is acceptable for WASM builds.

The release-wasm profile disables overflow checks (overflow-checks = false) to reduce binary size. This trades runtime safety for size optimization—arithmetic operations won't panic on overflow in this build. Ensure this is intentional and that the WASM code doesn't rely on overflow panics for correctness.

If overflow detection is required for any critical calculations, consider keeping overflow-checks = true or adding explicit validation in those code paths.

packages/orderbook/package.json (1)

35-35: LGTM! Build command correctly uses the new release-wasm profile.

The updated build-wasm script targets the specific rain_orderbook_js_api package with the size-optimized release-wasm profile, replacing the previous workspace-wide build approach.

packages/orderbook/scripts/build.js (2)

9-11: Type declaration paths updated correctly.

The .d.ts files now export from format-specific directories (./dist/cjs/index and ./dist/esm/index) instead of a shared ./dist/types/index, which aligns with the per-format build output structure.


21-28: Build orchestration is well-structured.

The per-package loop correctly invokes the build steps (CJS, ESM, size check) for each package. The sequential execution ensures proper dependency ordering.

packages/orderbook/scripts/buildEsm.js (3)

7-13: LGTM! wasm-bindgen invocation is correct for ESM output.

The script correctly targets the release-wasm profile output and generates web-compatible bindings to the temporary directory.


15-23: Base64 encoding eliminates runtime fetch/fs dependencies.

Embedding the WASM as base64 in a JSON file allows the ESM bundle to load the WASM synchronously without fetch or filesystem operations, which is essential for the Safari fix.


60-66: Synchronous initialization implements the Safari workaround.

The replacement removes the async initialization and instead calls initSync(bytes) immediately with the embedded base64-decoded WASM. This addresses the Safari top-level-await issue described in the PR objectives by ensuring synchronous initialization for ESM builds.

packages/orderbook/scripts/buildCjs.js (3)

7-13: LGTM! wasm-bindgen invocation is correct for CJS output.

The script correctly targets the release-wasm profile output and generates Node.js-compatible bindings to the temporary directory.


15-23: Inline WASM eliminates filesystem dependencies for CJS.

Embedding the WASM as base64 in a JSON file allows the CJS bundle to load the WASM without filesystem operations, ensuring the bindings are self-contained.


60-68: CJS replacement correctly inlines the WASM payload.

The script replaces the filesystem-based WASM loading with inline base64 decoding and removes the now-unnecessary util require for TextEncoder/TextDecoder. This ensures the CJS bundle is self-contained.

Comment thread packages/orderbook/scripts/buildCjs.js Outdated
Comment on lines +38 to +53
const dups = [
`export type WasmEncodedResult<T> = { value: T; error: undefined } | { value: undefined; error: WasmEncodedError };

export interface WasmEncodedError {
msg: string;
readableMsg: string;
}`
];
for (const dup of dups) {
const index = dts.indexOf(dup);
dts = dts.replaceAll(dup, "");
const start = dts.slice(0, index);
const end = dts.slice(index);
console.log(start.length, end.length)
dts = start + dup + end;
}

@coderabbitai coderabbitai Bot Oct 25, 2025

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 | 🔵 Trivial

Deduplication logic duplicated from buildEsm.js—consider extracting to shared utility.

This deduplication code is identical to buildEsm.js. The same issue exists: if indexOf returns -1 or the duplicate is at position 0, the slice logic may produce incorrect output.

  1. Extract the deduplication logic to a shared function in a common module
  2. Add defensive checks as suggested in buildEsm.js review

This would reduce code duplication and ensure both CJS and ESM builds handle edge cases consistently.

🤖 Prompt for AI Agents
In packages/orderbook/scripts/buildCjs.js around lines 38 to 53, the
deduplication loop copied from buildEsm.js incorrectly assumes dts.indexOf(dup)
will be >= 0 and mishandles index 0, and the logic is duplicated; extract this
deduplication into a shared utility (e.g.,
packages/orderbook/scripts/utils/dedupDts.js) and import it into both
buildCjs.js and buildEsm.js, and inside that utility add defensive checks:
compute index = dts.indexOf(dup) and if index === -1 skip; if index === 0 handle
slices safely (or simply perform a single replace that preserves the first
occurrence), ensure replaceAll usage is correct and that you reinsert the unique
block only after confirming a duplicate was removed; update both build scripts
to call the shared function so edge cases are handled consistently.

@rouzwelt rouzwelt Oct 25, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

its identical at this point but might not be in future, so its ok

Comment thread packages/orderbook/scripts/buildEsm.js Outdated
Comment on lines +1 to +11
const fs = require('fs');

const SIZE_LIMIT = 8_388_608; // 8 MB binary

const [pkg] = process.argv.slice(2);

// we only need to check size on web/esm
const wasmEsmBytes = fs.readFileSync(`./temp/web/${pkg}/${pkg}_bg.wasm`);
if (wasmEsmBytes.length > SIZE_LIMIT) {
throw new Error("ESM wasm size exceeds 8 MB limit!")
}

@coderabbitai coderabbitai Bot Oct 25, 2025

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 | 🔵 Trivial

Add error handling for missing package argument and file not found.

The script will throw an unhelpful error if the pkg argument is missing or if the WASM file doesn't exist. Consider adding explicit validation.

Apply these improvements:

 const fs = require('fs');
 
 const SIZE_LIMIT = 8_388_608; // 8 MB binary
 
 const [pkg] = process.argv.slice(2);
+
+if (!pkg) {
+    throw new Error("Package name argument is required");
+}
 
 // we only need to check size on web/esm
+const wasmPath = `./temp/web/${pkg}/${pkg}_bg.wasm`;
+if (!fs.existsSync(wasmPath)) {
+    throw new Error(`WASM file not found at ${wasmPath}`);
+}
-const wasmEsmBytes = fs.readFileSync(`./temp/web/${pkg}/${pkg}_bg.wasm`);
+const wasmEsmBytes = fs.readFileSync(wasmPath);
 if (wasmEsmBytes.length > SIZE_LIMIT) {
     throw new Error("ESM wasm size exceeds 8 MB limit!")
 }
🤖 Prompt for AI Agents
In packages/orderbook/scripts/sizeCheck.js around lines 1 to 11, the script
assumes a package argument and that the WASM file exists; add explicit
validation to (1) check that process.argv provides a pkg and throw a clear error
if missing, and (2) wrap the fs.readFileSync call in a try/catch or use
fs.existsSync to detect a missing file and throw a descriptive error mentioning
the expected path; ensure any thrown errors include the pkg value and expected
file path for easier debugging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not needed

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.

@rouzwelt, understood. I've noted your preference for these build scripts.


✏️ Learnings added
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/sizeCheck.js:1-11
Timestamp: 2025-10-25T21:11:09.656Z
Learning: In the rain.orderbook repository, build scripts like sizeCheck.js intentionally lack defensive error handling (e.g., checking for missing arguments or file existence). The scripts should fail with raw errors to surface configuration or build pipeline issues that require immediate attention.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildEsm.js:38-53
Timestamp: 2025-10-25T21:07:19.666Z
Learning: In the rain.orderbook repository, the deduplication logic in buildEsm.js (and similar build scripts) intentionally lacks defensive checks for indexOf returning -1. If duplicates are not found, the script should throw to surface breaking changes in wasm-bindgen output that require attention.

@rainlanguage rainlanguage deleted a comment from coderabbitai Bot Oct 25, 2025

@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.

Actionable comments posted: 2

♻️ Duplicate comments (1)
packages/orderbook/scripts/buildPackage.js (1)

117-120: Optional: add JSON import assertion and browser‑safe Buffer import.

Improves Node ESM correctness and forces the npm polyfill in browsers; confirm bundler support.

-import { Buffer } from 'buffer';
-import wasmB64 from './orderbook_wbg.json';
+import { Buffer } from 'buffer/'; // browser polyfill
+import wasmB64 from './orderbook_wbg.json' assert { type: 'json' };

If your toolchain doesn’t support JSON assertions, skip this. Please verify with your current Vite/SvelteKit versions.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1aed8f9 and 17ff7ca.

📒 Files selected for processing (3)
  • packages/orderbook/scripts/build.js (1 hunks)
  • packages/orderbook/scripts/buildPackage.js (1 hunks)
  • packages/orderbook/scripts/sizeCheck.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/orderbook/scripts/sizeCheck.js
  • packages/orderbook/scripts/build.js
  • packages/orderbook/scripts/buildPackage.js
🧠 Learnings (4)
📚 Learning: 2025-10-25T21:11:09.656Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/sizeCheck.js:1-11
Timestamp: 2025-10-25T21:11:09.656Z
Learning: In the rain.orderbook repository, build scripts like sizeCheck.js intentionally lack defensive error handling (e.g., checking for missing arguments or file existence). The scripts should fail with raw errors to surface configuration or build pipeline issues that require immediate attention.

Applied to files:

  • packages/orderbook/scripts/sizeCheck.js
📚 Learning: 2025-10-25T21:07:19.666Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildEsm.js:38-53
Timestamp: 2025-10-25T21:07:19.666Z
Learning: In the rain.orderbook repository, the deduplication logic in buildEsm.js (and similar build scripts) intentionally lacks defensive checks for indexOf returning -1. If duplicates are not found, the script should throw to surface breaking changes in wasm-bindgen output that require attention.

Applied to files:

  • packages/orderbook/scripts/sizeCheck.js
  • packages/orderbook/scripts/buildPackage.js
📚 Learning: 2025-10-25T21:06:38.462Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildCjs.js:38-53
Timestamp: 2025-10-25T21:06:38.462Z
Learning: In the rain.orderbook repository, build scripts in packages/orderbook/scripts/ (such as buildCjs.js and buildEsm.js) should keep duplicated logic separate rather than extracting to shared utilities, even when identical, to allow future divergence and to surface breaking changes as early failures.

Applied to files:

  • packages/orderbook/scripts/sizeCheck.js
  • packages/orderbook/scripts/build.js
  • packages/orderbook/scripts/buildPackage.js
📚 Learning: 2025-07-01T21:26:42.195Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#1955
File: packages/orderbook/package.json:40-40
Timestamp: 2025-07-01T21:26:42.195Z
Learning: In the rain.orderbook project, the team does not require cross-platform compatibility improvements for the TypeScript check script in packages/orderbook/package.json. The current brace expansion syntax "./dist/**/*.{ts,js}" is sufficient for their development environment.

Applied to files:

  • packages/orderbook/scripts/build.js
🧬 Code graph analysis (3)
packages/orderbook/scripts/sizeCheck.js (2)
packages/orderbook/scripts/build.js (4)
  • fs (1-1)
  • require (2-2)
  • require (3-3)
  • require (4-4)
packages/orderbook/scripts/buildPackage.js (3)
  • fs (1-1)
  • require (2-2)
  • wasmEsmBytes (83-83)
packages/orderbook/scripts/build.js (2)
packages/orderbook/scripts/buildPackage.js (2)
  • require (2-2)
  • fs (1-1)
packages/orderbook/scripts/sizeCheck.js (1)
  • fs (1-1)
packages/orderbook/scripts/buildPackage.js (1)
packages/orderbook/scripts/sizeCheck.js (2)
  • fs (1-1)
  • wasmEsmBytes (7-7)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Deploy-Docs-Preview
  • GitHub Check: Deploy-Preview-Push
🔇 Additional comments (4)
packages/orderbook/scripts/sizeCheck.js (1)

5-11: LGTM for the size gate.

Simple, deterministic check; matches the per‑package ESM flow. Based on learnings.

packages/orderbook/scripts/buildPackage.js (2)

39-52: DTS dedupe approach is acceptable here.

Keeps a single canonical block and re‑inserts once; matches the “fail loud” intent. Based on learnings.

Also applies to: 101-108


115-123: No breaking changes detected in repository consumers.

The verification search found only named imports from @rainlanguage/orderbook (e.g., RaindexClient, Float, DotrainOrderGui). No code in the repository imports the default export or calls an async init() function from the orderbook package. The change to synchronous inline initialization via initSync(bytes) does not affect any tracked consumers.

packages/orderbook/scripts/build.js (1)

20-27: Per‑package build + size gate looks good.

Flow is clear, minimal, and keeps failure surface localized post‑build.

Comment thread packages/orderbook/scripts/buildPackage.js
Comment thread packages/orderbook/scripts/sizeCheck.js

@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.

Actionable comments posted: 4

♻️ Duplicate comments (2)
packages/orderbook/scripts/buildPackage.js (2)

29-33: Avoid extra Buffer copy when base64‑encoding.

Use the existing Buffer directly; drop the redundant Buffer.from(..., 'binary').

 fs.writeFileSync(
   "./dist/cjs/orderbook_wbg.json",
   JSON.stringify({
-    wasm: Buffer.from(wasmCjsBytes, 'binary').toString('base64')
+    wasm: wasmCjsBytes.toString('base64')
   })
 );

85-89: Avoid extra Buffer copy (ESM JSON writer).

Same as CJS: use the original Buffer.

 fs.writeFileSync(
   `./dist/esm/orderbook_wbg.json`,
   JSON.stringify({
-    wasm: Buffer.from(wasmEsmBytes, 'binary').toString('base64')
+    wasm: wasmEsmBytes.toString('base64')
   })
 );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17ff7ca and 4202d01.

📒 Files selected for processing (1)
  • packages/orderbook/scripts/buildPackage.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/orderbook/scripts/buildPackage.js
🧠 Learnings (3)
📓 Common learnings
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1913
File: Cargo.toml:55-55
Timestamp: 2025-06-06T16:38:04.182Z
Learning: In rain.orderbook repository, during PR chains involving dependency updates, wasm-bindgen-utils may temporarily point to git commits that don't contain the full required functionality, with the understanding that subsequent PRs in the chain will update it to the correct commit.
📚 Learning: 2025-10-25T21:07:19.666Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildEsm.js:38-53
Timestamp: 2025-10-25T21:07:19.666Z
Learning: In the rain.orderbook repository, the deduplication logic in buildEsm.js (and similar build scripts) intentionally lacks defensive checks for indexOf returning -1. If duplicates are not found, the script should throw to surface breaking changes in wasm-bindgen output that require attention.

Applied to files:

  • packages/orderbook/scripts/buildPackage.js
📚 Learning: 2025-10-25T21:06:38.462Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildCjs.js:38-53
Timestamp: 2025-10-25T21:06:38.462Z
Learning: In the rain.orderbook repository, build scripts in packages/orderbook/scripts/ (such as buildCjs.js and buildEsm.js) should keep duplicated logic separate rather than extracting to shared utilities, even when identical, to allow future divergence and to surface breaking changes as early failures.

Applied to files:

  • packages/orderbook/scripts/buildPackage.js
🧬 Code graph analysis (1)
packages/orderbook/scripts/buildPackage.js (1)
packages/orderbook/scripts/sizeCheck.js (2)
  • fs (1-1)
  • wasmEsmBytes (7-7)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Deploy-Docs-Preview
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: Deploy-Preview-Push

Comment thread packages/orderbook/scripts/buildPackage.js
Comment thread packages/orderbook/scripts/buildPackage.js
Comment thread packages/orderbook/scripts/buildPackage.js
Comment thread packages/orderbook/scripts/buildPackage.js

@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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2734340 and d6af302.

📒 Files selected for processing (1)
  • packages/orderbook/scripts/build.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

JavaScript/Svelte projects live under packages/* (webapp, ui-components, orderbook)

Files:

  • packages/orderbook/scripts/build.js
🧠 Learnings (3)
📓 Common learnings
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildCjs.js:38-53
Timestamp: 2025-10-25T21:06:38.462Z
Learning: In the rain.orderbook repository, build scripts in packages/orderbook/scripts/ (such as buildCjs.js and buildEsm.js) should keep duplicated logic separate rather than extracting to shared utilities, even when identical, to allow future divergence and to surface breaking changes as early failures.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1744
File: crates/subgraph/src/orderbook_client.rs:44-46
Timestamp: 2025-05-14T05:13:59.713Z
Learning: In the rain.orderbook project, WASM dependencies are intentionally made available in non-WASM targets to facilitate testing of WASM-related functionality, so conditional compilation guards like `#[cfg(target_family = "wasm")]` should not be added to imports or implementations that may be needed for tests.
Learnt from: CR
PR: rainlanguage/rain.orderbook#0
File: AGENTS.md:0-0
Timestamp: 2025-10-06T08:05:50.452Z
Learning: WASM bundle via nix develop -c rainix-wasm-artifacts
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildEsm.js:38-53
Timestamp: 2025-10-25T21:07:19.666Z
Learning: In the rain.orderbook repository, the deduplication logic in buildEsm.js (and similar build scripts) intentionally lacks defensive checks for indexOf returning -1. If duplicates are not found, the script should throw to surface breaking changes in wasm-bindgen output that require attention.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1710
File: crates/quote/Cargo.toml:30-30
Timestamp: 2025-05-14T04:49:14.621Z
Learning: In the rain.orderbook repository, wasm-bindgen-utils is intentionally used as an unconditional dependency because non-wasm targets (like tests) sometimes need to use it.
📚 Learning: 2025-10-25T21:06:38.462Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#2246
File: packages/orderbook/scripts/buildCjs.js:38-53
Timestamp: 2025-10-25T21:06:38.462Z
Learning: In the rain.orderbook repository, build scripts in packages/orderbook/scripts/ (such as buildCjs.js and buildEsm.js) should keep duplicated logic separate rather than extracting to shared utilities, even when identical, to allow future divergence and to surface breaking changes as early failures.

Applied to files:

  • packages/orderbook/scripts/build.js
📚 Learning: 2025-07-01T21:26:42.195Z
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#1955
File: packages/orderbook/package.json:40-40
Timestamp: 2025-07-01T21:26:42.195Z
Learning: In the rain.orderbook project, the team does not require cross-platform compatibility improvements for the TypeScript check script in packages/orderbook/package.json. The current brace expansion syntax "./dist/**/*.{ts,js}" is sufficient for their development environment.

Applied to files:

  • packages/orderbook/scripts/build.js
🧬 Code graph analysis (1)
packages/orderbook/scripts/build.js (2)
packages/orderbook/scripts/buildPackage.js (2)
  • require (2-2)
  • fs (1-1)
packages/orderbook/scripts/sizeCheck.js (1)
  • fs (1-1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: Deploy-Docs-Preview
  • GitHub Check: Deploy-Preview-Push
🔇 Additional comments (2)
packages/orderbook/scripts/build.js (2)

2-4: Imports look correct.

The new imports for sizeCheck and the per-package build functions (buildCjs, buildEsm) are properly structured and align with the refactored build flow.


11-13: Build output structure is correct.

The verification confirms that buildCjs creates files at ./dist/cjs/index.d.ts and ./dist/cjs/index.js, while buildEsm creates files at ./dist/esm/index.d.ts and ./dist/esm/index.js. The type declaration paths in build.js lines 11 and 13 correctly reference these locations.

Comment thread packages/orderbook/scripts/build.js
@findolor
findolor enabled auto-merge October 30, 2025 16:59
@findolor
findolor merged commit 83a73c1 into main Oct 30, 2025
19 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment:

S/M/L PR Classification Guidelines:

This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed.

Small (S)

Characteristics:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

@coderabbitai

coderabbitai Bot commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

SIZE=L


🧠 Learnings used
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:42.275Z
Learning: For PR #1884, after each commit review, I should provide a new comment with a PR size report in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding irrelevant files such as lock files (package-lock.json, cargo.lock, etc.).

Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:42.275Z
Learning: After each commit in PR #1884, I should provide a new comment with the PR size report in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`. The report should exclude irrelevant files such as lock files (e.g., package-lock.json, cargo.lock).

Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:25:47.873Z
Learning: After each new commit review for rainlanguage/rain.orderbook repository, generate a PR size report in a separate comment with the format: "TOTAL=number ADDITIONS=number DELETIONS=number". This report should exclude irrelevant files such as lock files (e.g., package-lock.json, cargo.lock).

Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:25:47.873Z
Learning: After each new commit review for rainlanguage/rain.orderbook repository, generate a PR size report in a separate comment with the exact format: "TOTAL=number\nADDITIONS=number\nDELETIONS=number". This report should exclude irrelevant files such as lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).

Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.

Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any additional text or formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.

Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:46:08.530Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report should be the only content in the comment - no text before it, no text after it, no formatting blocks, just the raw report in the exact format: "TOTAL=number\nADDITIONS=number\nDELETIONS=number". The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).

Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.

Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.

Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.

Learnt from: findolor
PR: rainlanguage/rain.orderbook#1971
File: .github/workflows/vercel-docs-prod.yaml:32-34
Timestamp: 2025-07-11T12:30:09.245Z
Learning: findolor prefers not to pin Node versions explicitly in GitHub Actions workflows when using Nix with webapp-shell, considering the current setup sufficient for deterministic builds in the rainlanguage/rain.orderbook project.

Learnt from: findolor
PR: rainlanguage/rain.orderbook#1971
File: .github/workflows/vercel-docs-prod.yaml:10-14
Timestamp: 2025-07-11T12:29:49.284Z
Learning: In GitHub Actions workflows for the rainlanguage/rain.orderbook project, findolor is comfortable with job names that may seem misleading (like "Deploy-Docs-Preview" in a production workflow) when there's only one job in the workflow, as the context makes it clear enough.

Learnt from: brusherru
PR: rainlanguage/rain.orderbook#2036
File: crates/js_api/src/filters/raindex_filter_store.rs:446-533
Timestamp: 2025-08-02T02:34:32.237Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore WASM tests (crates/js_api/src/filters/raindex_filter_store.rs), brusherru decided to focus on testing only methods without side effects (that don't use web_sys) due to difficulties with mocking localStorage and window APIs in the WASM test environment. This pragmatic approach tests pure logic separately from browser integration.

Learnt from: findolor
PR: rainlanguage/rain.orderbook#1913
File: Cargo.toml:55-55
Timestamp: 2025-06-06T16:38:04.182Z
Learning: In rain.orderbook repository, during PR chains involving dependency updates, wasm-bindgen-utils may temporarily point to git commits that don't contain the full required functionality, with the understanding that subsequent PRs in the chain will update it to the correct commit.

Learnt from: findolor
PR: rainlanguage/rain.orderbook#1744
File: crates/subgraph/src/orderbook_client.rs:44-46
Timestamp: 2025-05-14T05:13:59.713Z
Learning: In the rain.orderbook project, WASM dependencies are intentionally made available in non-WASM targets to facilitate testing of WASM-related functionality, so conditional compilation guards like `#[cfg(target_family = "wasm")]` should not be added to imports or implementations that may be needed for tests.

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.

v5.raindex.finance order not visible in safari browser 500 for safari

3 participants