Fix webapp issue for Safari browser - #2246
Conversation
WalkthroughRefactors orderbook build to emit per-package CJS/ESM artifacts with base64-packed wasm JSON, adds an 8 MB wasm size check, introduces a Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (1)packages/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (29)📓 Common learnings📚 Learning: 2025-05-14T05:13:59.713ZApplied to files:
📚 Learning: 2025-10-06T08:05:50.452ZApplied to files:
📚 Learning: 2025-04-30T09:28:36.960ZApplied to files:
📚 Learning: 2025-05-14T04:49:14.621ZApplied to files:
📚 Learning: 2025-10-06T08:05:50.452ZApplied to files:
📚 Learning: 2025-05-19T13:40:56.080ZApplied to files:
📚 Learning: 2025-07-31T19:34:11.716ZApplied to files:
📚 Learning: 2025-08-02T02:34:32.237ZApplied to files:
📚 Learning: 2025-06-06T16:38:04.182ZApplied to files:
📚 Learning: 2025-07-18T10:31:05.498ZApplied to files:
📚 Learning: 2025-10-25T21:06:38.487ZApplied to files:
📚 Learning: 2025-07-01T21:26:42.195ZApplied to files:
📚 Learning: 2025-10-25T21:07:19.704ZApplied to files:
📚 Learning: 2025-10-19T20:24:08.629ZApplied to files:
📚 Learning: 2025-10-06T08:05:02.438ZApplied to files:
📚 Learning: 2025-05-21T23:09:27.578ZApplied to files:
📚 Learning: 2025-10-25T21:11:09.664ZApplied to files:
📚 Learning: 2025-10-06T08:05:02.438ZApplied to files:
📚 Learning: 2025-05-21T21:26:31.566ZApplied to files:
📚 Learning: 2025-10-06T08:05:02.438ZApplied to files:
📚 Learning: 2025-10-06T08:05:50.452ZApplied to files:
📚 Learning: 2025-10-06T08:05:50.452ZApplied to files:
📚 Learning: 2025-10-06T08:05:50.452ZApplied to files:
📚 Learning: 2025-10-06T08:05:50.452ZApplied to files:
📚 Learning: 2025-10-06T08:05:02.438ZApplied to files:
📚 Learning: 2025-07-11T12:30:09.245ZApplied to files:
📚 Learning: 2025-05-21T21:25:47.873ZApplied to files:
📚 Learning: 2025-05-21T21:24:53.708ZApplied to files:
🔇 Additional comments (3)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis 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.jspackages/ui-components/package.jsonpackages/webapp/package.jsonpackages/orderbook/package.jsonpackages/webapp/src/hooks.client.tspackages/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/webapppasses 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/webapppasses (required per project standards)npm -w @rainlanguage/webapp run buildsucceeds (hooks typing changes in SvelteKit 2.x may impact webapp)- Other workspace builds complete without errors
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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
inithook is properly typed asClientInit(fixing the previousServerInitissue), and thehandleErrorhook 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/webappfrom your local environment before pushing.
There was a problem hiding this comment.
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; considerbuffer/polyfill.From
dist/cjs/index.js, the JSON is alongside it, so require./orderbook_wbg.json. Usingbuffer/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, preferbuffer/.
index.jssits indist/esm/; use./orderbook_wbg.json. Addassert { type: 'json' }for Node ESM; usebuffer/. 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
📒 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.jspackages/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 ESMimport), 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:
- Document that the codebase requires Vite ≥5.0 (or your current tested version) for JSON import support, or
- 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.jsexplicitly generates bothdist/cjs/index.d.ts(line 46) anddist/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.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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.sveltepackages/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.sveltepackages/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 (
ClientInitandHandleClientError) for hooks.client.ts, and the/esmimport 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/esmimport 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. Ensurenpm run svelte-lint-format-check -w @rainlanguage/webapppasses locally before merging.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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
ClientInittype is correctly used (addressing the ServerInit issue from past reviews), andHandleClientErroris properly imported and used on line 15. The/esmsubpath import is intentional and webapp-specific.Based on learnings
11-13: Init hook correctly addresses the Safari issue.The
ClientInithook 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.
There was a problem hiding this comment.
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.jsand the JSON at./dist/cjs/${pkg}/orderbook_wbg.json, the path should be'./orderbook_wbg.json'. Additionally,wasmCjsBytesandwasmEsmBytesare already Buffers; wrapping them withBuffer.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
buildTypevalues:''(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
⛔ Files ignored due to path filters (1)
Cargo.lockis 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.jspackages/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.tomlcrates/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.tomlcrates/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.tomlcrates/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.tomlcrates/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_wrapperandjs_apipackages, supporting the new per-package build structure.
36-36: Commented check step — intentional or leftover?The
npm run checkstep 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_wrapperalongsidejs_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 asyncinit_wasm()function forjs_apibut performs only synchronous initialization forwasm_async_compile_wrapperwithout exporting a function. Verify this difference is intentional and that consumers ofwasm_async_compile_wrapperdon'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_wrappercrate atcrates/wasm_wrapper.crates/wasm_wrapper/src/lib.rs (1)
14-18: Async start function triggers init on module load.The
#[wasm_bindgen(start)]attribute ensurescompile_wasm_asyncruns automatically when the WASM module loads, calling into JSinit_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
cdylibfor WASM output with workspace-inherited metadata. The dependencies onfuturesandwasm-bindgen-utilsare appropriate for async WASM initialization. Per learnings,wasm-bindgen-utilsis intentionally unconditional to support testing.Based on learnings.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (2)
Cargo.lockis excluded by!**/*.locktauri-app/src-tauri/Cargo.lockis 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.jsonpackages/orderbook/package.jsonpackages/orderbook/scripts/buildEsm.jspackages/orderbook/scripts/build.jspackages/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.rspackages/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)
| 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; |
There was a problem hiding this comment.
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.
| 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.
There was a problem hiding this comment.
not needed, its ok
There was a problem hiding this comment.
@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.
| 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); | ||
| } | ||
| }` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@rouzwelt, understood. I'll note your decision to keep the current implementation as-is.
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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.jspackages/orderbook/scripts/build.jspackages/orderbook/scripts/sizeCheck.jspackages/orderbook/package.jsonpackages/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.tomlflake.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.tomlflake.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-wasmprofile 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-wasmprofile 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 = trueor 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-wasmscript targets the specificrain_orderbook_js_apipackage with the size-optimizedrelease-wasmprofile, replacing the previous workspace-wide build approach.packages/orderbook/scripts/build.js (2)
9-11: Type declaration paths updated correctly.The
.d.tsfiles now export from format-specific directories (./dist/cjs/indexand./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-wasmprofile 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-wasmprofile 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
utilrequire for TextEncoder/TextDecoder. This ensures the CJS bundle is self-contained.
| 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; | ||
| } |
There was a problem hiding this comment.
🧹 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.
- Extract the deduplication logic to a shared function in a common module
- 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.
There was a problem hiding this comment.
its identical at this point but might not be in future, so its ok
| 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!") | ||
| } |
There was a problem hiding this comment.
🧹 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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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
📒 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.jspackages/orderbook/scripts/build.jspackages/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.jspackages/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.jspackages/orderbook/scripts/build.jspackages/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 asyncinit()function from the orderbook package. The change to synchronous inline initialization viainitSync(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.
There was a problem hiding this comment.
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
📒 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
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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
sizeCheckand 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
buildCjscreates files at./dist/cjs/index.d.tsand./dist/cjs/index.js, whilebuildEsmcreates files at./dist/esm/index.d.tsand./dist/esm/index.js. The type declaration paths in build.js lines 11 and 13 correctly reference these locations.
|
@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:
Review Effort: Would have taken 5-10 minutes Examples:
Medium (M)Characteristics:
Review Effort: Would have taken 15-30 minutes Examples:
Large (L)Characteristics:
Review Effort: Would have taken 45+ minutes Examples:
Additional Factors to ConsiderWhen deciding between sizes, also consider:
Notes:
|
|
Tip For best results, initiate chat on the files or code changes. SIZE=L 🧠 Learnings used |
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-awaitspecially 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 whereClientInithook feature is available, this hook allows to do some asynchronous task before the web app is loaded and rendered. and we need to remove thetop-level-awaitin orderbook wasm package build script, provide a function initialization of the orderbook wasm module and initialize it in theClientInithook.To fix this, we ended up with workaround/hack solution, which is to make a think wrapper wasm crate that initializes thejs_api(or any other big wasm crate) on start usingwasm_bindgen(start)attribute, then on the build script forjs_apiweb 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 thejs_apiwasm 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-wasmcustom 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
checkandbuildcommand for orderbook pkg, which will throw an error if we ever hit 8MB limit.Note2: using the heavy size optimizations caused
WasmEncodedErrorandWasmEncodedResultts 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:
Summary by CodeRabbit