fix(ui): remove blocksHolder DOM listeners and detach holder on destroy#173
Closed
LocalhostTI wants to merge 1 commit into
Closed
fix(ui): remove blocksHolder DOM listeners and detach holder on destroy#173LocalhostTI wants to merge 1 commit into
LocalhostTI wants to merge 1 commit into
Conversation
- register BlocksUI's beforeinput/keydown listeners with an AbortController signal and abort them in destroy(); detach the blocks holder element as well - implement EditorjsUI.destroy() (was a no-op) to remove the editor wrapper from the holder - add the first test suite for @editorjs/ui (Jest + jsdom), written test-first per the TDD rule - add UI check CI workflow; skip base-coverage when the base ref has no test:coverage script; build workspace deps before vite build so jest can resolve them on a fresh runner - exclude *.spec.ts from published type declarations (vite-plugin-dts now uses tsconfig.build.json) - sync openspec/specs/ui/spec.md destroy scenarios Fixes #170
LocalhostTI
force-pushed
the
fix/ui-destroy-listeners
branch
from
July 20, 2026 20:56
791fc81 to
d7d5667
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes UI teardown leaks in @editorjs/ui by ensuring the blocks holder’s DOM listeners are removed and the holder/wrapper elements are detached during destroy(). It also introduces a Jest + jsdom test setup for the UI package and adds CI coverage for the package.
Changes:
- Add
AbortController-scopedbeforeinput/keydownlisteners toBlocksUIand abort + detach the blocks holder inBlocksUI.destroy(). - Implement real teardown in
EditorjsUI.destroy()by removing the editor wrapper from the holder. - Introduce
@editorjs/uiunit tests + Jest infrastructure, and add a dedicatedUI checkworkflow; update build + typings config to support co-located specs.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
yarn.lock |
Adds UI testing/build tool dependencies (Jest, ts-jest, jsdom, babel-jest). |
packages/ui/vite.config.ts |
Points vite-plugin-dts at tsconfig.build.json to avoid emitting spec d.ts stubs. |
packages/ui/test/mocks/styleMock.cjs |
Adds CSS-module identity proxy for Jest runs. |
packages/ui/src/index.ts |
Makes EditorjsUI.destroy() remove the editor wrapper element. |
packages/ui/src/index.spec.ts |
Adds unit coverage for EditorjsUI wrapper attachment/removal. |
packages/ui/src/Blocks/Blocks.ts |
Aborts holder DOM listeners on destroy and detaches the holder from the DOM. |
packages/ui/src/Blocks/Blocks.spec.ts |
Adds unit coverage for block rendering, input remapping, undo/redo shortcuts, and destroy cleanup. |
packages/ui/package.json |
Adds Jest scripts + deps; ensures build runs workspace dependency builds first. |
packages/ui/jest.config.ts |
Introduces Jest+ts-jest+jsdom config (ESM-friendly) for UI package tests. |
packages/ui/eslint.config.mjs |
Allows @jest/globals imports in spec files under published-import rules. |
openspec/specs/ui/spec.md |
Updates UI spec to reflect destroy behavior and new test coverage. |
.github/workflows/ui.yml |
Adds UI package CI workflow using the shared package-check pipeline. |
.github/actions/base-coverage/action.yml |
Skips base coverage when the base ref lacks a test:coverage script (new test suites). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+19
to
+20
| secrets: | ||
| stryker_dashboard_api_key: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #170
What
BlocksUInow registers itsblocksHolderDOM listeners (beforeinput,keydown) with anAbortControllersignal and aborts them indestroy(); the holder element itself is detached from the DOM as well.EditorjsUI.destroy()(previously a no-op) now removes the editor wrapper from the holder element.@editorjs/ui(Blocks.spec.ts,index.spec.ts, 14 tests) with Jest + jsdom infra mirroring thecorepackage setup. Written test-first (TDD): the destroy specs failed against the previous implementation.UI checkCI workflow (ui.yml, unit tests without mutations, modeled onmodel-types.yml).CI enablers (why this PR touches files outside
packages/ui).github/actions/base-coverage/action.yml: the guard now also skips base coverage when the base ref has notest:coveragescript. Without this, the base-coverage step would runyarn workspace @editorjs/ui test:coverageagainstmain(where the script doesn't exist yet) and fail. It flows through the same "missing base artifact" path that new packages already use (aggregate-reportdownloads artifacts withcontinue-on-error).packages/uibuild script:buildnow runsbuild:deps(topological workspace-deps build) beforevite build. Every other package builds viatsc --buildwhose project references transitively build workspace deps into theirdist/;uiis the first vite-built package through theunit-testsaction, and vite externalizes@editorjs/*, so on a fresh runnerpackages/sdk/distwould never exist and jest could not resolve@editorjs/sdk(reproduced locally by wiping dep dists). This makesui's build behave like thetsc --buildpackages — matching the build action's "Build the package with dependencies" step.packages/ui/vite.config.ts:dts()now usestsconfig.build.json(which excludessrc/**/*.spec.ts); otherwise the new co-located specs leak empty*.spec.d.tsstubs into the publisheddist/.Notes for reviewers
copylistener — that one is introduced by feat(core): implement Clipboard Plugin #129, which is not merged yet, so this PR covers the two listeners that exist onmain. Once feat(core): implement Clipboard Plugin #129 lands, itscopylistener can simply join the sameAbortSignal.EventBus(non-DOM) subscriptions made in theBlocksUI/EditorjsUIconstructors are intentionally untouched: the bus lives and dies with the editor instance. Happy to tackle that as a follow-up if you'd like.openspec/specs/ui/spec.mdgets destroy scenarios and a refreshed test-suite note (openspec validate uipasses). Noopenspec/changes/proposal folder — small behavior bug fix with the spec delta applied directly, same approach as feat(core): implement Clipboard Plugin #129. Can convert to a full proposal if preferred.GITHUB_TOKENis read-only and theAggregate and post reportjob (which posts the coverage comment) will fail with 403. That's the repo-widepackage-check.ymlpattern, not something this PR changes — lint/tests/build jobs are unaffected. This will be the first fork PR to exercise the report job since it was introduced.Verification
packages/ui:yarn lint:ci(0 warnings),yarn test(14/14),yarn build— all green locallyyarn workspaces foreach -A run clear(nodist/, notsbuildinfoanywhere), the CI sequenceyarn workspace @editorjs/ui run build && yarn workspace @editorjs/ui test:coveragepassesyarn constraintsand rootyarn buildpass;npx openspec validate uipasses