Skip to content

fix(sdk): make optional lifecycle hooks non-abstract - #1260

Open
txnioh wants to merge 1 commit into
InditexTech:mainfrom
txnioh:fix/sdk-optional-lifecycle-hooks
Open

txnioh wants to merge 1 commit into
InditexTech:mainfrom
txnioh:fix/sdk-optional-lifecycle-hooks

Conversation

@txnioh

@txnioh txnioh commented Nov 3, 2026 •

Copy link
Copy Markdown

Closes #1256

Problem

WeaveNode, WeaveAction and WeavePlugin declare their optional hooks as abstract name?(): void. TypeScript requires abstract members to be implemented even when they are marked optional, so a subclass that leaves one out fails with TS2515. The SDK always calls these hooks with ?.(), and the API reference describes them as optional ("if defined").

The SDK works around it with hook = undefined;: there are 72 such lines in sdk/src, 22 in weavejs-frontend and weavejs-backend, and the pattern is in .github/copilot-instructions.md. Anyone who does not know the pattern gets the error. Since #994 (3.7.0) added initialize this way, every custom node, action and plugin written before that release fails to type-check after upgrading. The create-weave-*-app templates are an example: their actions set onPropsChange = undefined but not initialize.

Change

abstract is removed from the 8 optional hooks, which stay optional:

  • nodes/node.ts: initialize
  • actions/action.ts: initialize, onInit, onPropsChange, cleanup
  • plugins/plugin.ts: initialize, onInit, onRender

abstract only exists in the types, so the emitted JavaScript does not change. The required members (onRender/onUpdate on nodes, trigger on actions, enable/disable on plugins) are untouched.

All existing code keeps compiling: subclasses that implement a hook, subclasses that set it to undefined, and subclasses that leave it out. I checked the hook signatures used in the SDK, the templates and the two showcase repos: all of them are (): void, and none calls super.<hook>() or uses override.

Tests

src/__tests__/types/optional-hooks.test-d.ts is a type-level test. It defines a minimal node, action and plugin with no hooks, plus an action that uses the = undefined pattern.

The SDK's tsconfig.json excludes __tests__ and vitest did not type-check, so a regular test could not catch this. To run the new test, vitest.config.ts enables typecheck, scoped by src/__tests__/types/tsconfig.json to *.test-d.ts files. The folder's tsconfig.json is already covered by REUSE.toml's **/tsconfig.json.

  • On main, npm run test -w @inditextech/weave-sdk exits 1: MinimalNode does not implement initialize (TS2515).
  • With this change it exits 0: 162 files and 5762 tests pass (5760 + the 2 new ones).

Verification

  • npm run verify in code/ (the CI command) passes for all 10 projects on this branch, with no Nx cache hits.
  • SDK: vitest (162 files, 5762 tests), tsc --noEmit, eslint and the package build pass.
  • prettier --check is clean on the changed files. sdk/src already has 156 files that prettier reports on main, and I left them alone.
  • reuse lint: compliant (1728/1728).
  • sanitize-changelog.mjs --check and commitlint pass.
  • With the change applied to the published 5.7.1 types, the generated frontend goes from 18 to 15 type errors (the 3 TS2515 are gone), and the generated backend has 0 once the template fixes from Generated create-weave-*-app projects do not install, build or run without manual fixes #1257 are in.

Out of scope:

If you would rather not enable typecheck in the SDK's vitest config, I can drop the type test and keep only the 8-line change.

Suggested label: release-type/patch. I can't set labels myself.

@txnioh
txnioh requested a review from a team as a code owner November 3, 2026 00:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T00:46:41.392912Z 4403fbb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@signoff-validator

signoff-validator Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Contribution License Agreement - Valid 🟢

All commits contain valid signoff. As a confirmation, remember that you are agreeing to our Contribution License Agreement.

Closes InditexTech#1256

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: txnio <bytxnio@gmail.com>

This branch has not been deployed

No deployments
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.

Optional lifecycle hooks declared abstract force every custom node, action and plugin to implement them

1 participant