Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build-canvas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- main
pull_request:
paths:
- ".github/workflows/*"
- "crates/*"
- ".github/workflows/**"
- "crates/**"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
- main
pull_request:
paths:
- ".github/workflows/*"
- "crates/*"
- ".github/workflows/**"
- "crates/**"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
5 changes: 3 additions & 2 deletions bin/activate-emsdk
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ EMSDK_ROOT = os.path.join('third_party', 'externals', 'emsdk')

EMSDK_PATH = os.path.join(EMSDK_ROOT, 'emsdk.py')

# This should match what's in //MODULE.bazel
EMSDK_VERSION = '4.0.7'
# Keep this aligned with the emsdk submodule and local builds.
# (The emsdk git submodule is currently at 5.0.0.)
EMSDK_VERSION = '5.0.0'

def main():
if sysconfig.get_platform() in ['linux-aarch64', 'linux-arm64']:
Expand Down
1 change: 0 additions & 1 deletion crates/grida-canvas-wasm/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ rustflags = [
# Allow undefined symbols (useful for dynamic linking and Skia integration)
"-C",
"link-arg=-sERROR_ON_UNDEFINED_SYMBOLS=0",
# Currently only targeting web (fs=false)
# Target both web (browser) and Node.js.
# NOTE: this affects the generated Emscripten JS glue (loader/runtime selection).
"-C",
Expand Down
13 changes: 2 additions & 11 deletions crates/grida-canvas-wasm/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,16 @@ Note: the artifacts are git included for faster CI builds.

When building the WASM glue with `-sENVIRONMENT=web,node`, Emscripten emits a Node-only branch that uses Node built-ins (`fs`, `path`, sometimes `crypto`). Some bundlers (notably **Next.js Turbopack**) will still try to resolve those built-ins when the module is imported from a Client Component and fail with **"Can't resolve 'fs'"**.

We keep a **single package** that works in both browser and Node by combining three measures:

- **Patch Emscripten glue to use `node:*` built-ins**
- Script: `scripts/prebuild-patch-emscripten-js-glue.cjs`
- Patched file: `lib/bin/grida-canvas-wasm.js`
- Rewrites `require("fs")` → `require("node:fs")`, `require("path")` → `require("node:path")`, `require("crypto")` → `require("node:crypto")`
- Reference issue: `https://github.com/emscripten-core/emscripten/issues/26134`
We keep a **single package** that works in both browser and Node by ensuring the Emscripten glue is not bundled into `dist/index.*`:

- **Do NOT bundle the Emscripten glue into `dist/index.*`**
- `lib/index.ts` imports `./grida-canvas-wasm` (a thin wrapper)
- Wrapper: `lib/grida-canvas-wasm.ts` imports `./bin/grida-canvas-wasm`
- `tsup.config.ts` sets `external: ["./grida-canvas-wasm"]` and copies `lib/bin/*` via `publicDir`
- Result: `dist/index.js` only imports `./grida-canvas-wasm`, and the actual glue stays as `dist/grida-canvas-wasm.js` (copied), so Turbopack never sees Node built-ins inside the bundled entry.

- **Run the glue patch before bundling**
- `package.json` uses `prebuild` to patch `lib/bin/grida-canvas-wasm.js` before `tsup` runs.

⚠️ Notes:
- Simply setting `tsup.external` to `["node:fs", "node:path", ...]` is **not sufficient** here; bundling the glue can still produce `require("fs")` in `dist/index.js`, which breaks Turbopack.
- Simply setting `tsup.external` to `["node:fs", "node:path", ...]` is **not sufficient** here; bundling the glue can still produce Node built-in imports in `dist/index.js`, which breaks Turbopack.
- If you change `lib/index.ts` to import `./bin/grida-canvas-wasm` directly (no wrapper + external), re-verify `pnpm --filter editor build` with Turbopack.

## Build System
Expand Down
23 changes: 21 additions & 2 deletions crates/grida-canvas-wasm/lib/bin/grida-canvas-wasm.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/grida-canvas-wasm/lib/bin/grida_canvas_wasm.wasm
Git LFS file not shown
3 changes: 1 addition & 2 deletions crates/grida-canvas-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grida/canvas-wasm",
"version": "0.90.0-canary.0",
"version": "0.90.0-canary.2",
"private": false,
"description": "WASM bindings for Grida Canvas",
"keywords": [
Expand All @@ -21,7 +21,6 @@
"main": "dist/index.js",
"scripts": {
"build": "tsup",
"prebuild": "node ./scripts/prebuild-patch-emscripten-js-glue.cjs",
"dev": "tsup --watch",
"serve": "serve -p 4020",
"test": "vitest run",
Expand Down

This file was deleted.

7 changes: 0 additions & 7 deletions crates/grida-canvas/src/io/io_grida.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,6 @@ pub struct JSONBooleanOperationNode {
fn default_active() -> bool {
true
}
fn default_locked() -> bool {
false
}
fn default_false() -> bool {
false
}
Expand All @@ -1218,10 +1215,6 @@ fn default_opacity() -> f32 {
fn default_rotation() -> f32 {
0.0
}
fn default_z_index() -> i32 {
0
}

fn default_stroke_width() -> f32 {
0.0
}
Expand Down
7 changes: 4 additions & 3 deletions crates/grida-dev/src/platform/native_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use super::winit::{winit_window, WinitResult};
use cg::node::schema::Size;
use cg::resources::{FontMessage, ImageMessage};
use cg::runtime::camera::Camera2D;
use cg::runtime::scene::Backend;
use cg::window::application::{ApplicationApi, HostEvent, UnknownTargetApplication};
use cg::window::command::ApplicationCommand;
use cg::window::state::AnySurfaceState;
use futures::channel::mpsc;
use glutin::{
context::PossiblyCurrentContext,
Expand Down Expand Up @@ -114,7 +114,7 @@ impl NativeApplication {
fit_scene_on_load: bool,
) -> (Self, EventLoop<HostEvent>) {
let WinitResult {
mut state,
state,
el,
window,
gl_surface,
Expand All @@ -128,7 +128,8 @@ impl NativeApplication {
height: height as f32 * scale_factor as f32,
});

let backend = Backend::GL(state.surface_mut_ptr());
let mut state = AnySurfaceState::from_gpu(state);
let backend = state.backend();
let redraw_cb: Arc<dyn Fn()> = {
let redraw_proxy = proxy.clone();
Arc::new(move || {
Expand Down
Loading