Skip to content

Upgrade hocuspocus v3, Elasticsearch client v9, and related dependencies#9

Merged
MrOrz merged 11 commits intomasterfrom
upgrade-es-v9
Apr 9, 2026
Merged

Upgrade hocuspocus v3, Elasticsearch client v9, and related dependencies#9
MrOrz merged 11 commits intomasterfrom
upgrade-es-v9

Conversation

@nonumpa
Copy link
Copy Markdown
Member

@nonumpa nonumpa commented Apr 8, 2026

Summary

  • Upgrade @hocuspocus/* from v2 to v3.4.4
  • Upgrade @elastic/elasticsearch from v6 to v9
  • Update rumors-db submodule to latest master
  • Upgrade yjs ecosystem packages (yjs, y-prosemirror)
  • Update CI: Elasticsearch 9.2.2, Node 24

Changes

Hocuspocus v2 → v3

  • Server.configure({...})new Server({...})
  • Provider uses shared websocketProvider with attach()/detach()

Elasticsearch v6 → v9

  • Named import: import { Client } from '@elastic/elasticsearch'
  • Remove body wrapper — params go directly
  • index(): bodydocument
  • update(): body: { doc, script }doc, script directly
  • Response: result.bodyresult directly
  • bulk(): bodyoperations

CI

  • ES docker: elasticsearch-oss:6.3.2elasticsearch:9.2.2
  • Node: 18 → 24

nonumpa added 8 commits April 8, 2026 16:39
Upgrade @hocuspocus/server, extension-logger, extension-database, provider, and transformer from v2.x to v3.4.4. Also bump yjs to 13.6.30 and y-prosemirror to 1.3.7.
In hocuspocus v3, Server.configure() was removed. Use the constructor directly.
Pull rumors-db from 032b83e to 71a0f36. Major changes include migration of schema files from .js to .ts, ES6 to ES9 migration, and new badges schema.
- Use named imports: import { Client, type ClientOptions } from '@elastic/elasticsearch'
- Remove 'type' parameter (document types removed in ES 9)
- Unwrap 'body' parameter in update/get calls
- Use 'document' instead of 'body' for index calls
- Remove '.body' wrapper from responses
- Add type parameters to get() calls for type safety
Migrate Hocuspocus/Configuration to Server/ServerConfiguration, remove deprecated broadcast/quiet options, fix server.listen() return type, and add provider.attach() required by v3 for shared websocketProvider.
- Migrate test ES client calls to v9 API (named imports, no type param, no body wrapper)
- Use port 0 instead of hardcoded 1234 to avoid EADDRINUSE
- Add test document cleanup to prevent test pollution
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 8, 2026

Coverage Report for CI Build 24178351899

Coverage decreased (-14.9%) to 75.581%

Details

  • Coverage decreased (-14.9%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (8 of 10 lines covered, 80.0%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
hocuspocus-extension-elasticsearch/src/elasticsearch.ts 5 3 60.0%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
hocuspocus-extension-elasticsearch/src/elasticsearch.ts 1 59.46%

Coverage Stats

Coverage Status
Relevant Lines: 47
Covered Lines: 42
Line Coverage: 89.36%
Relevant Branches: 39
Covered Branches: 23
Branch Coverage: 58.97%
Branches in Coverage %: Yes
Coverage Strength: 1.23 hits per line

💛 - Coveralls

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request upgrades the project to Elasticsearch v9 and Hocuspocus v3. The changes involve updating dependency versions in package.json files, refactoring Elasticsearch client interactions to use the updated API (e.g., removing the type parameter and flattening request structures), and migrating from the Hocuspocus class to the Server class. Review feedback suggests applying more consistent optional chaining in error handling logic within src/snapshot.ts to improve robustness.

Comment thread src/snapshot.ts
Comment thread src/snapshot.ts
@nonumpa nonumpa requested a review from MrOrz April 8, 2026 16:27
Copy link
Copy Markdown
Member

@MrOrz MrOrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update looks great! However, docker image build is somehow broken, so I cannot deploy it on staging. Would you take a look @nonumpa ?

https://github.com/cofacts/collab-server/actions/runs/24156795262/job/70497811406#step:6:294

Migration scripts use legacy ES v6 API and are run manually via
ts-node, not as part of the Docker image. Excluding them from tsc
fixes the build failure without needing to port dead migration code
to the v9 client API.
@nonumpa
Copy link
Copy Markdown
Member Author

nonumpa commented Apr 9, 2026

Fixed and the build passed

@nonumpa nonumpa requested a review from MrOrz April 9, 2026 01:49
@nonumpa
Copy link
Copy Markdown
Member Author

nonumpa commented Apr 9, 2026

Note that there's also an yjs-upgrade in rumors-site.

@MrOrz
Copy link
Copy Markdown
Member

MrOrz commented Apr 9, 2026

It seems that something is missing in the build process, so that the built image cannot start

圖片

@MrOrz
Copy link
Copy Markdown
Member

MrOrz commented Apr 9, 2026

Probably Dockerfile is using a node js version that is too old. Upgrading to Node 24 should help

nonumpa added 2 commits April 9, 2026 15:27
@elastic/elasticsearch v9 depends on undici which requires the global
File API (available since Node.js 20). The Docker image was still using
Node 18, causing 'ReferenceError: File is not defined' at startup.

Aligns Dockerfile with CI which already uses Node 24.
…fier-resolution

--experimental-specifier-resolution=node was removed in Node 22+.
Add .js extensions to all relative imports so ESM resolution works
natively without the flag on Node 24.
@nonumpa
Copy link
Copy Markdown
Member Author

nonumpa commented Apr 9, 2026

Sorry about that! The Dockerfile was still on Node 18, which doesn't have the global File API that undici (used by @elastic/elasticsearch v9) needs — hence the ReferenceError: File is not defined.

Upgraded both stages to node:24-alpine in 5d1c71b, but that exposed another issue: --experimental-specifier-resolution=node was removed in Node 22, so ESM imports without .js extensions broke with ERR_MODULE_NOT_FOUND. Fixed in a5ac672 by adding explicit .js extensions to all relative imports and dropping the flag.

build: https://github.com/cofacts/collab-server/actions/runs/24178547334/job/70565538065

Copy link
Copy Markdown
Member

@MrOrz MrOrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is working perfectly on staging! Thanks for the timely fix m(_ _)m

Image Image

@MrOrz MrOrz merged commit 8512c88 into master Apr 9, 2026
4 checks passed
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.

3 participants