Skip to content

feat(react): export the current API from @deck.gl/react/legacy - #11181

Merged
chrisgervang merged 9 commits into
masterfrom
chr/react-legacy-subpath
Nov 19, 2026
Merged

chrisgervang merged 9 commits into
masterfrom
chr/react-legacy-subpath

Conversation

@chrisgervang

@chrisgervang chrisgervang commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #11039

Background

In v10 the package root becomes the React renderer (#11036), and the current API stays at @deck.gl/react/legacy. This adds that subpath first, so apps can move to it before the root changes.

Change List

  • @deck.gl/react/legacy subpath export, same API as the root
  • Module sources moved to src/legacy, re-exported from the root
  • build-cjs.mjs module build script: the CommonJS root requires ./legacy/index.cjs instead of inlining a second copy, so both entries share one React context
  • tsconfig and vitest aliases for the subpath
  • Unit tests
  • Documentation

Verified with yarn lint, the headless tests for test/modules/react, and a clean build of the module's ES and CommonJS entries, and the node test that bundles both CommonJS entries.


Generated by Claude Code


Note

Low Risk
Low risk refactoring that adds a legacy subpath export for the current React API without modifying runtime behavior.

Overview
Prepares for the upcoming v10 React Fiber renderer by exposing the existing React API at @deck.gl/react/legacy while preserving full backwards compatibility at the package root.

The React module's source files have been relocated to src/legacy/, re-exported from src/index.ts, and published via new package ./legacy subpath exports and TypeScript typesVersions definitions. A custom CommonJS build script (build-cjs.mjs) ensures the root bundle requires the /legacy CommonJS entry rather than inlining a second copy, preventing split React context instances.

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


Generated by Claude Code

Move the module's sources under src/legacy and re-export them from the
package root, and add a ./legacy subpath export. The root API is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn
@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no blocking issues were found.

Summary

Adds @deck.gl/react/legacy while keeping the existing root API unchanged.

  • Apps can keep using the current React API through @deck.gl/react/legacy.

No new actionable issues found.

Reviews (7) · Last reviewed commit: "Merge remote-tracking branch 'origin/mas..." · Reviewed by Greptile

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread modules/react/src/index.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 18, 2026

Copy link
Copy Markdown

Comments Outside Diff

These findings could not be posted inline.

  • P1 Benchmarks import a removed file modules/react/src/legacy/utils/inherits-from.ts:6 ▶

    Benchmarks import a removed file. Moving this helper leaves test/bench/utils.bench.js importing @deck.gl/react/utils/inherits-from. yarn bench loads that file through the main benchmark page, but the source alias now points to a directory without utils. The page cannot load its benchmarks. Update the benchmark import to @deck.gl/react/legacy/utils/inherits-from.

  • P2 Source links point nowhere modules/react/src/legacy/deckgl.ts:6 ▶

    Source links point nowhere. The React API pages still link to modules/react/src/deckgl.ts and modules/react/src/utils/use-widget.ts. Both files move under legacy here, so those links will return 404 after merging. Update both source links to the new paths.

@coveralls

coveralls commented Nov 18, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 82.522% (+0.001%) from 82.521% — chr/react-legacy-subpath into master

@ibgreen ibgreen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CommonJS packaging needs a shared legacy implementation before this serves as an incremental migration path. Ocular bundles dist/index.cjs and dist/legacy/index.cjs independently, so they each create a different DeckGlContext. A widget/custom component using useWidget from one entry cannot consume the provider from the other entry.

I reproduced this at 6a8cc49 by bundling both source entries with the project's CJS settings (bundle: true, packages: 'external'). They expose the same names but different DeckGL/useWidget identities and two distinct contexts. With real React/ReactDOM server and stubbed deck imports, a cross-entry hook under the other entry's captured provider throws Cannot destructure property 'widgets' of 'context' as it is undefined; the same-entry control registers the widget. This was a focused diagnostic, not a full package/browser build.

The new source-alias identity test misses this because both imports resolve to the same TypeScript module. Could the CJS root forward to the legacy CJS entry (or otherwise share its implementation), with a built-entry regression test? This matters when an application switches to /legacy while a reusable component still imports the current root. The ESM re-export does not duplicate the context.

ocular's build-cjs bundles each `require` entry separately with only packages
external, so `dist/index.cjs` inlined its own copy of `/legacy`, with its own
DeckGL context. A component calling `useWidget` from one entry could not see a
`DeckGL` from the other.

The root now re-exports `@deck.gl/react/legacy` by package name, so its CJS
bundle is a `require` of the legacy bundle. The default export is re-exported by
name, because the CJS interop would otherwise make `default` the whole
`module.exports` object. A node test bundles both entries with the build-cjs
settings and checks the root requires `/legacy` and shares its identities.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn
Comment thread modules/react/src/index.ts Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 236c2ec. Configure here.

Comment thread modules/react/src/index.ts Resolved

chrisgervang commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks, confirmed and fixed.

  • CommonJS: modules/react/build-cjs.mjs (a module build script run after ocular-build, as in CARTO) rebuilds the require entries so that an import of another entry's file becomes a relative require of that entry's bundle. dist/index.cjs is now require("./legacy/index.cjs"), 1.2 kB with no implementation of its own (checked on a clean build). The source keeps relative imports, so the ESM files and declarations resolve without exports (398744c; an earlier package-name self import, 236c2ec, broke moduleResolution: node).
  • Default export: re-exported by name (export {DeckGL as default}). Otherwise the CJS interop in this "type": "module" package makes the root's default the whole legacy module.exports.
  • Test: test/modules/react/legacy-cjs.node.spec.ts bundles both entries with the script's own options, checks the root requires ./legacy/index.cjs and has no createContext, then evaluates both bundles with real React and stubbed deck imports and checks DeckGL, useWidget and default are identical. It fails on 6a8cc49.

#11183 had the same problem across the root, the three map roots and /reconciler; it uses the same script, with a test that fails if any stateful module is bundled into more than one CJS entry.


Generated by Claude Code

Importing `@deck.gl/react/legacy` by package name left that specifier in
`dist/index.js` and `dist/index.d.ts`, which TypeScript with
`moduleResolution: node` and bundlers that ignore `exports` can't resolve.

The root imports `./legacy/index` again. A module build script, run after
ocular-build like CARTO's, rebuilds the CommonJS entries so that an import of
another entry's file becomes a relative `require` of that entry's bundle:
`dist/index.cjs` is `require("./legacy/index.cjs")`. The node test bundles the
entries with the script's own options and checks the root has no relative
package import.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn
Comment thread modules/react/build-cjs.mjs Resolved
chrisgervang pushed a commit that referenced this pull request Nov 18, 2026
…cjs.mjs

Takes #11181's module build script and goes back to relative imports: the DOM
root imports `../reconciler/index` and the map roots `../index`, which the
script turns into requires of `./reconciler/index.cjs` and `../index.cjs`, so
no published file imports `@deck.gl/react` by package name. The root keeps the
renderer, so #11181's root-to-legacy test doesn't apply; the entries test now
bundles with the script's options and also checks the source has no
package-name self imports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn

Copy link
Copy Markdown
Collaborator Author

test-coverage failed on 510b2f9 with a "WebGL context is lost" cascade that started after test/modules/maplibre/globe-icons-text.spec.ts. It isn't from this PR: 398744c and 0c13a10 (the current head) differ from it only in comments, and both pass test-coverage and test-webgpu. The cause is WebGL contexts that existing browser tests leave open in the shared headless page; #11183 adds test/setup/release-webgl-contexts.ts, which releases each file's contexts.


Generated by Claude Code

@ibgreen ibgreen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Retested 0c13a10: the CommonJS context issue from my earlier review is fixed. I emitted the module, ran the actual build-cjs.mjs, packed it, and loaded both entries from an extracted consumer package with real React and stubbed deck dependencies. All runtime export identities (including default) match, only one context is created, and the cross-entry useWidget control now registers successfully. This is focused packaging verification, not a full repository build/browser run; declaration emission used noCheck.

One migration limitation remains: a consumer using moduleResolution: "node" can import the root again, but switching that import to @deck.gl/react/legacy still produces TS2307. The package has no root-level legacy declaration or typesVersions mapping; its exports map is only honored by newer resolution modes. I verified root and /legacy both resolve with node16/bundler, while only root resolves with node.

Since this entry is specifically intended to let existing applications migrate before the root changes, could we add the legacy declaration mapping (and a packed consumer test), or document the required resolution-mode change? This is distinct from the now-fixed root self-import regression.

TypeScript's `node` resolution ignores `exports`, so `@deck.gl/react/legacy`
failed with TS2307 for apps still on it. `typesVersions` now maps `legacy` to
`dist/legacy/index.d.ts`. A node test checks that every `exports` subpath has a
`typesVersions` entry for the same declarations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn

Copy link
Copy Markdown
Collaborator Author

Thanks for retesting. Reproduced the TS2307 and fixed it in 74936d3: typesVersions now maps legacy to dist/legacy/index.d.ts.

Checked with a packed consumer (npm pack, extracted into a fresh node_modules, TypeScript 6.0): both @deck.gl/react and @deck.gl/react/legacy resolve under node, node16 and bundler, and --traceResolution shows them landing on dist/index.d.ts and dist/legacy/index.d.ts. Before the change only the root resolved under node.

For CI, test/modules/react/package-types.node.spec.ts checks that every exports subpath has a typesVersions entry pointing at the same declarations, so a new subpath can't skip it. I didn't add a packed-consumer job, since CI tests don't build dist; I can add one to the build workflow if you want it.


Generated by Claude Code

chrisgervang pushed a commit that referenced this pull request Nov 18, 2026
Takes #11181's `typesVersions` fix and its test, and maps every renderer subpath
(`/mapbox`, `/maplibre`, `/google-maps`, the component subpaths and
`/reconciler`), so they resolve under `moduleResolution: node` too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn

@ibgreen ibgreen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified the typesVersions fix at 74936d3. In a freshly extracted packed consumer, both root and /legacy resolve and the named/default component and props-type imports compile under node, node16, and bundler. The packed CJS checks also still pass: all export identities match, there is one context, and the cross-entry widget hook registers successfully. Both findings from my earlier reviews are addressed.

Verification scope: focused module emission using the repository's append-extension transforms (noCheck for emission), the actual CJS build helper, and TypeScript consumer checks with skipLibCheck; runtime checks used real React with stubbed deck dependencies. This is not a full local repository/browser test pass. The hosted test workflow for this head is successful.

@chrisgervang
chrisgervang merged commit 64cf9d4 into master Nov 19, 2026
9 checks passed
@chrisgervang
chrisgervang deleted the chr/react-legacy-subpath branch November 19, 2026 07:02
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.

react: move the current module to @deck.gl/react/legacy

4 participants