Skip to content

fix(editor): simplify globalScope to globalThis and inline at its one call site#2647

Merged
christianhg merged 2 commits into
mainfrom
refactor/global-scope-globalthis
May 12, 2026
Merged

fix(editor): simplify globalScope to globalThis and inline at its one call site#2647
christianhg merged 2 commits into
mainfrom
refactor/global-scope-globalthis

Conversation

@christianhg
Copy link
Copy Markdown
Member

@christianhg christianhg commented May 11, 2026

getGlobalScope had a four-branch chain - globalThis first, then window, self, global. globalThis is universal in every environment the editor supports (browsers, Node 12+, workers, Deno, Bun), so the rest of the chain is unreachable.

Beyond being dead code, the global branch needs @types/node in scope to type-check. Consumers whose tsconfig doesn't pull Node types - any app that aliases @portabletext/editor directly to its src/ rather than going through the built lib/ - trip on it. The racetrack app at apps/racetrack/ (PR #2646) ran into it on Vercel where deps build from scratch and stale tsbuildinfo caches don't hide it.

With the four-branch fallback gone, global-scope.ts is a one-line passthrough whose only job is to suppress symbol-indexing on globalThis with as any. There's nothing left to wrap. Inline the cast at the one call site in createGloballyScopedContext and delete the file.

No public API change, no behaviour change.

`getGlobalScope` had a chain - `globalThis` first, then `window`, `self`,
`global`. `globalThis` is universal in every environment the editor
supports (browsers, Node 12+, workers, Deno, Bun), so the rest of the
chain is unreachable.

Beyond being dead, the `global` branch needs `@types/node` in scope to
type-check. Consumers whose tsconfig doesn't pull Node types - any app
that aliases `@portabletext/editor` directly to its `src/` - tripped
on it. Simplify to a single `globalThis` read.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

🦋 Changeset detected

Latest commit: 32a52a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@portabletext/editor Patch
@portabletext/plugin-character-pair-decorator Patch
@portabletext/plugin-emoji-picker Patch
@portabletext/plugin-input-rule Patch
@portabletext/plugin-markdown-shortcuts Patch
@portabletext/plugin-one-line Patch
@portabletext/plugin-paste-link Patch
@portabletext/plugin-sdk-value Patch
@portabletext/plugin-typeahead-picker Patch
@portabletext/plugin-typography Patch
@portabletext/toolbar Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
portable-text-editor-documentation Ready Ready Preview, Comment May 12, 2026 7:18am
portable-text-example-basic Ready Ready Preview, Comment May 12, 2026 7:18am
portable-text-playground Ready Ready Preview, Comment May 12, 2026 7:18am
racetrack Ready Ready Preview, Comment May 12, 2026 7:18am

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

ghost commented May 11, 2026

📦 Bundle Stats — @portabletext/editor

Compared against main (52da58bb)

@portabletext/editor

Metric Value vs main (52da58b)
Internal (raw) 745.0 KB +874 B, +0.1%
Internal (gzip) 142.9 KB +109 B, +0.1%
Bundled (raw) 1.35 MB +874 B, +0.1%
Bundled (gzip) 303.9 KB +122 B, +0.0%
Import time 97ms -0ms, -0.0%

@portabletext/editor/behaviors

Metric Value vs main (52da58b)
Internal (raw) 467 B -
Internal (gzip) 207 B -
Bundled (raw) 424 B -
Bundled (gzip) 171 B -
Import time 3ms +0ms, +2.0%

@portabletext/editor/plugins

Metric Value vs main (52da58b)
Internal (raw) 3.3 KB -307 B, -8.4%
Internal (gzip) 948 B -73 B, -7.1%
Bundled (raw) 3.1 KB -307 B, -8.9%
Bundled (gzip) 878 B -74 B, -7.8%
Import time 8ms -0ms, -2.5%

@portabletext/editor/selectors

Metric Value vs main (52da58b)
Internal (raw) 76.3 KB -
Internal (gzip) 14.3 KB -
Bundled (raw) 72.4 KB -
Bundled (gzip) 13.3 KB -
Import time 8ms -0ms, -1.2%

@portabletext/editor/traversal

Metric Value vs main (52da58b)
Internal (raw) 9.2 KB -
Internal (gzip) 2.4 KB -
Bundled (raw) 9.3 KB -
Bundled (gzip) 2.4 KB -
Import time 5ms -0ms, -0.1%

@portabletext/editor/utils

Metric Value vs main (52da58b)
Internal (raw) 30.6 KB -
Internal (gzip) 6.5 KB -
Bundled (raw) 28.4 KB -
Bundled (gzip) 6.1 KB -
Import time 7ms +0ms, +2.1%

🗺️ . · ./behaviors · ./plugins · ./selectors · ./traversal · ./utils · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

…and delete the dead `global-scope` helper

With the Node `global` fallback gone, `global-scope.ts` is a one-line passthrough whose only job is to suppress symbol-indexing on `globalThis` with `as any`. The wrapper has nothing left to wrap.

Inline the cast at the single call site in `createGloballyScopedContext` and delete the file. No public API, no behaviour change.
@christianhg christianhg changed the title refactor(editor): drop dead Node global fallback in globalScope fix(editor): simplify globalScope to globalThis and inline at its one call site May 12, 2026
@christianhg christianhg enabled auto-merge (rebase) May 12, 2026 07:20
@christianhg christianhg merged commit 703e4a9 into main May 12, 2026
18 checks passed
@christianhg christianhg deleted the refactor/global-scope-globalthis branch May 12, 2026 07:23
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.

1 participant