Skip to content

Gnome: register custom GTypes before templates - #110

Merged
JumpLink merged 1 commit into
mainfrom
fix/106-widget-registration
Jun 8, 2026
Merged

Gnome: register custom GTypes before templates#110
JumpLink merged 1 commit into
mainfrom
fix/106-widget-registration

Conversation

@JumpLink

@JumpLink JumpLink commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Problem

After #103 (dependency + oxc formatter bump), running yarn && yarn build && yarn start aborts while building the main window with:

Gtk-CRITICAL: Error building template class 'Learn' ...: Invalid object type 'TutorialView'
Gtk-CRITICAL: Error building template class 'Editor' ...: Invalid object type 'QuickHelpView'
... Custom constructor for class Learn returned NULL ...
TypeError: can't access property "events", this._sourceView is null

No usable window opens. Fixes #106.

Root cause

Blueprint templates reference custom widgets by their GTypeName (e.g. $TutorialView, $QuickHelpView, $SourceView). A custom type must be registered with the GObject type system before any template embedding it is instantiated.

Each widget module self-registers via its static GObject.registerClass(...) block (plus a trailing GObject.type_ensure(...)), but that code only runs if the module is actually evaluated. Several consumers import their child widgets with import type { ... } (e.g. main.window.ts imports Learn/Editor/GameConsole/Debugger as types). The bundler strips type-only imports entirely, so those modules were never pulled into the bundle and never registered. The dependency/formatter bump in #103 changed the bundling so the latent bug started biting.

The rebuilt binary grew from ~531 KB to ~731 KB, confirming the widget modules were previously being tree-shaken out.

Fix

Add src/register-types.ts, a side-effect import barrel for every self-registering widget/view/dialog module, loaded early from main.ts (before Application is constructed). This guarantees all GTypes exist before the first window template is built.

Verification

  • yarn check:typescript (gjsify tsc) passes.
  • yarn check:format passes.
  • App starts cleanly (default locale and Hebrew/RTL LC_ALL=he_IL.UTF-8 LANGUAGE=he): no Invalid object type, no returned NULL, no related JS errors; all views (learn/editor/debugger/game console) build and the simulator runs.

Blueprint templates reference custom widgets by GTypeName (e.g.
$TutorialView, $QuickHelpView, $SourceView). Those types must be
registered before a template embedding them is instantiated, or GTK
aborts with "Invalid object type '<Name>'".

Each widget self-registers on module load, but several consumers
imported their children with `import type { ... }`, which the bundler
strips entirely — so the modules were never evaluated/registered. This
surfaced after the dependency/formatter bump in #103.

Add src/register-types.ts, a side-effect import barrel for every
self-registering widget/view module, loaded early from main.ts so all
GTypes exist before the first window template is built.

Fixes #106
@JumpLink
JumpLink merged commit 70543c0 into main Jun 8, 2026
3 checks passed
@JumpLink
JumpLink deleted the fix/106-widget-registration branch June 8, 2026 20:07
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.

runtime error after #103

1 participant