Skip to content

internal(website): Declare playground editor globals with valid TypeScript - #4136

Merged
ntucker merged 24 commits into
masterfrom
claude/project-thread-ynhl0c
Oct 5, 2026
Merged

ntucker merged 24 commits into
masterfrom
claude/project-thread-ynhl0c

Conversation

@ntucker

@ntucker ntucker commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Requested by Nathaniel · project thread

Follow-up from the Staff review on #4104.

Motivation

Before: typeLibs.ts registered four libs as declare globals { … }, which is not TypeScript. Playground globals still typed only because TS parser error recovery turns that into an expression plus a block in a script file, leaking everything inside to global scope. DateTimeFormat (not an export of the temporal lib) silently became any, use and mockFetch (both in the preview scope) were "Cannot find name", and TextInput/TextArea/Formatted props referenced unresolved names (InputHTMLAttributes, Formatter), so they were any.

After: every extra lib is valid TS with zero lib diagnostics. The same globals type-check, and the missing ones are now typed:

// no imports, in any playground
const [n] = React.useState(0);
const todos = useSuspense(TodoResource.getList);
DateTimeFormat('en-US', { dateStyle: 'medium' }).format(Temporal.Now.instant()); // was any, now typed
const user = use(promise); // was "Cannot find name 'use'"
const fetchTodos = mockFetch(() => todos, 'getTodos'); // was "Cannot find name 'mockFetch'"
<NumberFlow value={n} />;
<strike>x</strike>;

Solution

  • editor-types/globals.d.ts is mounted as an ambient module (playground-globals), with type dropped from its export list. Then one module-file lib aliases each export into declare global with export import X = _globals.X, alongside React, JSX (= React.JSX), use, NumberFlow, Temporal, DateTimeFormat, BigNumber and Manager. Array/Object stay built-in (they would redeclare lib globals; schema.Array works).
  • The <strike> JSX augmentation now targets declare module 'react'.
  • Preview-scope declarations add mockFetch, and TextInput/TextArea/Formatted use React.* types. TextArea uses TextareaHTMLAttributes (in the component too), since InputHTMLAttributes lacks rows and would have flagged docs/core/shared/_useLoading.mdx.
  • Includes internal(website): Type React jsx-runtime, path-to-regexp and bignumber.js in playgrounds #4137 and internal(website): Type csstype and number-flow in playgrounds #4139 (module typing follow-ups: react/jsx-runtime, path-to-regexp, bignumber.js), merged into this branch.

Verification

  • Real browser (docs dev server, Monaco 0.56 / TS 5.9.3): recorded Monaco markers on 39 docs pages with playgrounds before and after. They are identical. A probe model confirms React, Temporal, NumberFlow, data-client exports, JSX.Element and <strike> resolve as before, DateTimeFormat/use are now typed, and unknown names still error.
  • Offline TS 5.9.3 harness running the real addTypeLibs over all 143 playgrounds (348 files across docs/ incl. Vue, blog and homepage demos): 0 files with changed diagnostics.
  • yarn workspace rdc-website typecheck, yarn lint and Playground tests clean.

Notes

Names only typed before through the leak (e.g. Controller, State, internal $1 helpers) are no longer global. No docs playground uses them without importing. A global Intl is not redeclared since it would clash with the lib's Intl.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TkVym3YjjuSjBKhLLwvZm6


Note

Low Risk
Changes are limited to docs playground Monaco typings and editor-types build scripts; runtime preview behavior is unchanged aside from stricter TypeScript on design-system props.

Overview
Replaces invalid declare globals { … } Monaco extra libs with proper module mounting and a globalScopeLib() that aliases preview-scope exports (from rollup globals.d.ts via playground-globals) into declare global using export import, alongside React, use, NumberFlow, Temporal, DateTimeFormat, and BigNumber. Array/Object are skipped so built-in types stay intact.

Editor-types pipeline: copywebsitetypes.sh now strips csstype comments, fixes react/jsx-runtime imports, copies path-to-regexp and updated bignumber.js typings, and runs a single editor-types.rollup.config.js (replacing separate uuid/globals rollups) to bundle uuid, inlined @number-flow/react, and globals.

typeLibs.ts adds csstype, react/jsx-runtime, and path-to-regexp module libs; moves the <strike> JSX augmentation to declare module 'react'; and extends preview-scope declarations (mockFetch, React.* prop types). TextArea and mockFetch in scope.ts get matching type fixes (TextareaHTMLAttributes, generics).

Reviewed by Cursor Bugbot for commit 67c0524. Bugbot is set up for automated code reviews on this repo. Configure here.

claude and others added 13 commits October 3, 2026 15:18
Split the 362-line monaco-init into focused modules (setup, typeLibs,
theme, navigation, modelPath), group preview execution under preview/,
and replace forwarding modules with direct imports. Behavior is
unchanged; the new README documents the SSR, incremental-loading,
mobile/bot and hidden-tab invariants a future change must keep.

- monaco/: setup side effect, table-driven type libs (same chunks and
  order), cross-tab navigation, `/<id>/<path>` model URI helpers
- editor/: InteractiveEditor (Monaco or mobile react-live) and
  StaticEditor (SSR/crawler/loading markup)
- userAgent.ts: one source for bot/mobile regexes (isGoogleBot → isBot)
- Remove PlaygroundEditor, PlaygroundLiveEditor, DiffEditorChooser
  aliases, the unused readOnly prop, and unreferenced resources/
- Unit tests for highlight selections and model paths

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015H36Yk4WBpytw9L7RRVCTK
CI runs Playground unit tests without website dependencies installed,
so parse the highlight range in InteractiveEditor and pass line numbers.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015H36Yk4WBpytw9L7RRVCTK
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015H36Yk4WBpytw9L7RRVCTK
…ffEditorChooser, readOnly and resources

Keep these entry points and the readOnly option available for future
use; they now point at the reorganized editor modules.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015H36Yk4WBpytw9L7RRVCTK
cf2de88 brought the dead files and the unused editor prop back.
This commit restores the deletions Staff already accepted.

Review: #4104 (review)

Co-authored-by: Nathaniel Tucker <me@ntucker.me>
Reverts 82bf2d0 per Nathaniel's choice to keep PlaygroundEditor,
DiffEditorChooser, the readOnly prop and Playground/resources for now.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015H36Yk4WBpytw9L7RRVCTK
…hain

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015H36Yk4WBpytw9L7RRVCTK
…re path= metastrings

Import completions for relative paths now list only files from the same
playground instead of every Monaco model on the page. Fence metastrings
accept unquoted path=a.ts (used in docs/rest/api/RestEndpoint.md). Also
prettier-formats the Playground README.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015H36Yk4WBpytw9L7RRVCTK
…cript

`declare globals { … }` is not TypeScript; the playground globals only typed
because parser error recovery leaked the wrapped declarations into global
scope, and DateTimeFormat silently became `any`.

Mount editor-types/globals.d.ts as a module and alias its exports, React,
JSX, NumberFlow, Temporal, DateTimeFormat and Manager into `declare global`.
Also type TextInput/TextArea/Formatted props that referenced unresolved names.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkVym3YjjuSjBKhLLwvZm6
@changeset-bot

changeset-bot Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 67c0524

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@ntucker ntucker self-assigned this Oct 4, 2026
@vercel

vercel Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docs-site Ready Ready Preview Oct 5, 2026 3:29am UTC

Request Review

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkVym3YjjuSjBKhLLwvZm6
@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.06%. Comparing base (74e67fa) to head (60c44b2).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4136   +/-   ##
=======================================
  Coverage   98.06%   98.06%           
=======================================
  Files         163      163           
  Lines        3095     3095           
  Branches      616      616           
=======================================
  Hits         3035     3035           
  Misses         18       18           
  Partials       42       42           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…er.js in playgrounds (#4137)

Mount real declarations for `react/jsx-runtime` (was an empty stub),
`path-to-regexp` (never mounted, so @data-client/rest's PathFunction and
ParamData were unresolved) and `bignumber.js` (stub whose types were never
mounted), and declare `BigNumber` as a playground global since the preview
scope provides it.


Claude-Session: https://claude.ai/code/session_01W5R8xxJwz7dAy3Uk2v5eH5

Co-authored-by: Claude <noreply@anthropic.com>
* internal(website): Type React jsx-runtime, path-to-regexp and bignumber.js in playgrounds

Mount real declarations for `react/jsx-runtime` (was an empty stub),
`path-to-regexp` (never mounted, so @data-client/rest's PathFunction and
ParamData were unresolved) and `bignumber.js` (stub whose types were never
mounted), and declare `BigNumber` as a playground global since the preview
scope provides it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W5R8xxJwz7dAy3Uk2v5eH5

* internal(website): Type csstype and number-flow in playgrounds

React's CSSProperties and NumberFlow's props resolved through unmounted
modules, so style values and NumberFlow format/trend/plugins were any.
Mount csstype (comments stripped, 85KB -> 31KB gzipped) and a bundled
number-flow/lite; number-flow/plugins re-exports from it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SP4rqYKdew65uNyP8xeJ9m

* internal(website): Bundle @number-flow/react types with number-flow

Bundle @number-flow/react's .d.ts with its number-flow/lite and
number-flow/plugins imports inlined, instead of mounting those as
separate modules with a hand-written plugins stub. uuid and number-flow
now share one editor-types rollup config and resolver.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SP4rqYKdew65uNyP8xeJ9m

---------

Co-authored-by: Claude <noreply@anthropic.com>
claude added 3 commits October 4, 2026 09:14
…e-lib helpers

- One metaValue() parser for title= and path= (quotes optional for both)
- One anchored model-id regex; stripModelId is a replace
- Mark preview-scope global libs in MODULE_LIBS instead of modules[0]
- language is required on InteractiveEditor (codeModel always sets it)
- Drop unused return from Monaco setup

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015H36Yk4WBpytw9L7RRVCTK
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkVym3YjjuSjBKhLLwvZm6
…to claude/project-thread-ynhl0c

# Conflicts:
#	website/src/components/Playground/monaco/typeLibs.ts
Base automatically changed from claude/project-thread-9udgck to master October 4, 2026 16:32
#4104 landed on master; keep this branch's typeLibs.ts and README.md.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkVym3YjjuSjBKhLLwvZm6
claude added 2 commits October 5, 2026 03:24
Bundle globals.d.ts from the editor-types rollup config (one rollup run,
identical output), make mockFetch generic to match its editor declaration,
and trim the README note.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkVym3YjjuSjBKhLLwvZm6
@ntucker
ntucker merged commit 19a6628 into master Oct 5, 2026
22 checks passed
@ntucker
ntucker deleted the claude/project-thread-ynhl0c branch October 5, 2026 03:41

This branch was successfully deployed

1 active deployment
Preview — 67c0524b Deployed Oct 5, 2026 by vercel[bot]
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