Skip to content

[fix] Restore reactJsonViewCompat shim for local dev server#14391

Merged
lukasmasuch merged 2 commits intodevelopfrom
lukasmasuch/restore-json-compat
Mar 17, 2026
Merged

[fix] Restore reactJsonViewCompat shim for local dev server#14391
lukasmasuch merged 2 commits intodevelopfrom
lukasmasuch/restore-json-compat

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Mar 16, 2026

Describe your changes

Restores the reactJsonViewCompat.ts compatibility shim that was removed in #14380. The direct import from @microlink/react-json-view works in CI builds but fails when running locally with the dev server (e.g., make debug or make frontend-dev).

Changes:

  • Restored frontend/lib/src/util/reactJsonViewCompat.ts with updated imports for @microlink/react-json-view
  • Updated Json.tsx, useJsonTooltip.ts, and JsonViewer.tsx to import through the compat shim

Why this is needed:

  • @microlink/react-json-view is published as CommonJS
  • Vite 8 interop can yield different runtime module shapes (module, module.default, module.default.default) depending on the optimization path
  • Without normalization, Json components fail with "Element type is invalid" errors in local dev

GitHub Issue Link (if applicable)

Testing Plan

  • Unit Tests (existing tests pass)
  • Manual testing with make debug to verify Json elements render correctly

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

Agent metrics
Type Name Count
subagent fixing-pr 1
subagent general-purpose 1

The direct import from @microlink/react-json-view works in CI but fails
when running locally with the hot-reload dev server due to Vite 8
CommonJS interop issues causing "Element type is invalid" errors.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@lukasmasuch lukasmasuch added change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Mar 16, 2026
Copilot AI review requested due to automatic review settings March 16, 2026 21:52
@lukasmasuch lukasmasuch added change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Mar 16, 2026
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Mar 16, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 16, 2026

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-14391/streamlit-1.55.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-14391.streamlit.app (☁️ Deploy here if not accessible)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a Vite 8 compatibility shim for @microlink/react-json-view (CommonJS) to ensure the JSON viewer renders reliably across different Vite dependency-optimization module shapes, and updates internal consumers to use the shim.

Changes:

  • Introduces reactJsonViewCompat.ts to normalize nested default exports via resolveDefaultExport.
  • Switches DataFrame JSON cell viewer and the JSON element to import the ReactJson component (and related types) from the compat shim.
  • Updates JSON tooltip hook to import OnSelectProps from the compat shim to keep type usage consistent.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
frontend/lib/src/util/reactJsonViewCompat.ts New shim to normalize @microlink/react-json-view default export shape under Vite 8.
frontend/lib/src/components/widgets/DataFrame/columns/cells/JsonViewer.tsx Uses the compat ReactJson import for DataFrame JSON cell overlays.
frontend/lib/src/components/elements/Json/useJsonTooltip.ts Imports OnSelectProps from the shim to align with the new import path.
frontend/lib/src/components/elements/Json/Json.tsx Uses the compat ReactJson import and pulls OnCopyProps from the shim.

Add comprehensive unit tests for the resolveDefaultExport function that
handles CommonJS module interop under Vite 8. Tests cover:
- Various module shapes (no wrapper, single default, double nested)
- Depth limiting behavior
- Edge cases (null, undefined, primitives, arrays)

This addresses the review feedback requesting test coverage for the
compatibility shim to prevent regressions during Vite/dependency upgrades.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@lukasmasuch lukasmasuch added the ai-review If applied to PR or issue will run AI review workflow label Mar 16, 2026
@github-actions github-actions bot removed the ai-review If applied to PR or issue will run AI review workflow label Mar 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Summary

This PR restores the reactJsonViewCompat.ts compatibility shim for @microlink/react-json-view that was removed in #14380. The direct import works in CI builds but fails in the local Vite 8 dev server (make debug / make frontend-dev) due to inconsistent CommonJS interop behavior. The shim uses the existing resolveDefaultExport utility (from the Vite 7→8 upgrade, #14359) to normalize nested default export wrappers. The PR also adds comprehensive unit tests for resolveDefaultExport, which previously lacked dedicated test coverage.

Changed files:

  • frontend/lib/src/util/reactJsonViewCompat.ts — new compat shim (updated for @microlink/react-json-view)
  • frontend/lib/src/util/resolveDefaultExport.test.ts — new unit tests for resolveDefaultExport
  • frontend/lib/src/components/elements/Json/Json.tsx — import switched to compat shim
  • frontend/lib/src/components/elements/Json/useJsonTooltip.ts — type import switched to compat shim
  • frontend/lib/src/components/widgets/DataFrame/columns/cells/JsonViewer.tsx — import switched to compat shim

Code Quality

All three reviewers agreed the code is clean, well-structured, and follows existing codebase patterns. Specific points of consensus:

  • reactJsonViewCompat.ts has excellent JSDoc documentation explaining intent, rationale, removal criteria, and Vite references.
  • The implementation is a thin, centralized wrapper that delegates to the generic resolveDefaultExport utility and re-exports relevant types.
  • Import paths use the ~lib/ alias consistently.
  • The bounded maxDepth approach in resolveDefaultExport avoids unbounded object traversal.

No blocking code quality issues identified by any reviewer.

Test Coverage

All reviewers agreed test coverage is adequate:

  • resolveDefaultExport.test.ts provides comprehensive coverage with 14 test cases across three describe blocks, covering CommonJS interop shapes (no wrapper, single/double/triple nested defaults), depth limiting, and edge cases (null, undefined, primitives, arrays, objects without default).
  • Existing Json.test.tsx and JsonViewer.test.tsx implicitly validate the compat shim by rendering through it.
  • No new E2E tests are needed — this is a build-infrastructure fix with no user-facing behavior change.

Minor gap (non-blocking, noted by gpt-5.3-codex-high): No integration-style test directly verifies reactJsonViewCompat against mocked module namespace shapes end-to-end.

Backwards Compatibility

Unanimous agreement: No breaking changes. This restores a previously-existing pattern from the Vite 8 upgrade. The public API and component behavior are unchanged. Type re-exports (OnCopyProps, OnSelectProps) maintain the same API surface for consuming files.

Security & Risk

Unanimous agreement: No security concerns.

External test recommendation

  • Recommend external_test: No
  • Triggered categories: None
  • Evidence: All changes are confined to frontend module import paths. No routing, auth, WebSocket, embedding, asset serving, cross-origin, storage, or security header changes.
  • Confidence: High (unanimous across all reviewers)

Accessibility

Unanimous agreement: No accessibility impact. Rendered DOM and interactive elements are unchanged; only internal import paths are modified.

Recommendations

No blocking issues. Minor non-blocking suggestions from individual reviewers:

  1. (gpt-5.3-codex-high): Optionally add a focused unit test for reactJsonViewCompat that mocks @microlink/react-json-view module namespace shapes and asserts the default export is callable.
  2. (opus-4.6-thinking): Consider adding a brief comment in the test file linking it to reactJsonViewCompat.ts as the primary consumer of resolveDefaultExport, to help future developers understand why this utility has dedicated tests.
  3. (opus-4.6-thinking): The resolveDefaultExport early-exit on falsy resolvedValue means a module with { default: 0 } or { default: "" } would not unwrap. This is fine for the current use case (React components are always truthy), but a brief JSDoc note about this assumption would be helpful if the utility is ever generalized.

Verdict

APPROVED: All three reviewers unanimously approved. The PR is a clean, well-documented restoration of a necessary Vite 8 CommonJS compatibility shim for @microlink/react-json-view, with thorough test coverage for the underlying utility. No breaking changes, no security concerns, and low regression risk.


This is a consolidated AI review by opus-4.6-thinking.


📋 Review by `gemini-3.1-pro`

Summary

This PR restores the reactJsonViewCompat.ts compatibility shim for @microlink/react-json-view that was removed in a previous PR (#14380). It fixes an "Element type is invalid" error that occurs during local development with Vite 8 due to varying CommonJS interop module shapes.

Code Quality

The code quality is excellent. The compatibility shim is well-documented with clear intent, reasoning, and removal criteria. The resolveDefaultExport utility is clean and robust.

Test Coverage

The new resolveDefaultExport.test.ts provides comprehensive unit test coverage, including standard cases, deep nesting limits, and edge cases (null, undefined, primitives, arrays, etc.). Existing unit tests for the Json components should continue to pass.

Backwards Compatibility

There are no breaking changes. This is a purely internal fix for the development environment and will not affect existing users.

Security & Risk

No security concerns or regression risks identified. The changes are isolated to frontend module resolution for a specific component.

External test recommendation

  • Recommend external_test: No
  • Triggered categories: None
  • Evidence:
    • frontend/lib/src/util/reactJsonViewCompat.ts: Only modifies how a third-party dependency is imported to handle Vite 8 interop.
  • Suggested external_test focus areas: N/A
  • Confidence: High
  • Assumptions and gaps: None

Accessibility

No accessibility impact. The changes only affect module resolution, not the rendered DOM or interactive elements.

Recommendations

None. The changes are solid and ready to merge.

Verdict

APPROVED: The PR effectively resolves the local development issue with a robust, well-tested compatibility shim.


This is an automated AI review by gemini-3.1-pro.

📋 Review by `gpt-5.3-codex-high`

Summary

This PR restores a compatibility shim for @microlink/react-json-view to handle Vite 8 CommonJS interop differences seen in local dev servers. It reroutes JSON viewer imports through reactJsonViewCompat and adds focused unit tests for nested default-export unwrapping.

Code Quality

The change is well-scoped and maintainable:

  • Import-path updates are minimal and centralized in frontend/lib/src/util/reactJsonViewCompat.ts.
  • The shim has clear intent, removal criteria, and references to Vite behavior.
  • frontend/lib/src/util/resolveDefaultExport.test.ts provides good edge-case coverage for wrapper depth and primitive/null inputs.

No blocking code quality issues found.

Test Coverage

Coverage is good for the utility behavior introduced:

  • Added unit tests in frontend/lib/src/util/resolveDefaultExport.test.ts cover direct, single/double/triple nested defaults and depth limiting behavior.
  • Existing component tests for JSON rendering (Json and JsonViewer) continue to exercise rendering paths that consume the compat import.

Minor gap (non-blocking): this does not add an integration-style test that directly verifies reactJsonViewCompat against mocked module namespace shapes end-to-end.

Backwards Compatibility

No public API changes or protocol changes are introduced. This is backwards compatible and specifically restores local-dev behavior (make debug/make frontend-dev) that regressed after shim removal.

Security & Risk

No security-sensitive surfaces are changed:

  • No auth/session/cookie/XSRF logic changes.
  • No routing/WebSocket/server endpoint modifications.
  • No new external requests, runtime code execution patterns, or dependency additions.

Primary risk is limited to JSON component rendering if unexpected module shapes exceed current unwrap depth; current implementation intentionally bounds depth.

External test recommendation

  • Recommend external_test: No
  • Triggered categories: None
  • Evidence:
    • frontend/lib/src/util/reactJsonViewCompat.ts: frontend-only module interop normalization; no routing/auth/network/storage/policy changes.
    • frontend/lib/src/components/elements/Json/Json.tsx: import source switched to compat shim only.
    • frontend/lib/src/components/elements/Json/useJsonTooltip.ts: type import source switched only.
    • frontend/lib/src/components/widgets/DataFrame/columns/cells/JsonViewer.tsx: import source switched to compat shim only.
    • frontend/lib/src/util/resolveDefaultExport.test.ts: unit tests for export resolution helper.
  • Suggested external_test focus areas:
    • Optional smoke-only check in externally hosted/embedded deployment that JSON elements still render (not required by current risk profile).
    • Optional parity check between production build and local dev server JSON rendering.
  • Confidence: High
  • Assumptions and gaps: Review is diff-based only; no runtime execution was performed in this pass.

Accessibility

No accessibility-impacting DOM/interaction changes were introduced. This PR only changes import wiring and utility behavior, so existing a11y characteristics remain unchanged.

Recommendations

  1. Optional: add one focused unit test for reactJsonViewCompat that mocks @microlink/react-json-view module namespace shapes and asserts the default export is callable.

Verdict

APPROVED: The fix is narrowly scoped, addresses the reported local-dev regression, preserves backward compatibility, and introduces adequate utility-level test coverage.


This is an automated AI review by gpt-5.3-codex-high. Please verify the feedback and use your judgment.

📋 Review by `opus-4.6-thinking`

Summary

This PR restores the reactJsonViewCompat.ts compatibility shim that was removed in #14380 when migrating from react-json-view to @microlink/react-json-view. The direct import from @microlink/react-json-view works in CI builds but fails in the local Vite 8 dev server (e.g., make debug or make frontend-dev) due to inconsistent CommonJS interop behavior. The shim uses the existing resolveDefaultExport utility (introduced in the Vite 7→8 upgrade, #14359) to normalize nested default export wrappers. Additionally, the PR adds comprehensive unit tests for resolveDefaultExport, which previously had no dedicated test coverage.

Changed files:

  • frontend/lib/src/util/reactJsonViewCompat.ts — new file restoring the compat shim (updated for @microlink/react-json-view)
  • frontend/lib/src/util/resolveDefaultExport.test.ts — new test file for the existing resolveDefaultExport utility
  • frontend/lib/src/components/elements/Json/Json.tsx — import changed from direct @microlink/react-json-view to compat shim
  • frontend/lib/src/components/elements/Json/useJsonTooltip.ts — type import changed to compat shim
  • frontend/lib/src/components/widgets/DataFrame/columns/cells/JsonViewer.tsx — import changed to compat shim

Code Quality

The code is clean, well-structured, and follows existing patterns in the codebase:

  • reactJsonViewCompat.ts: Excellent documentation with JSDoc explaining intent, why it exists, removal criteria, and Vite references. The implementation is a thin wrapper that delegates to the generic resolveDefaultExport utility and re-exports the relevant types. This is essentially the same pattern as the shim from the Vite 8 upgrade (chore: upgrade vite v7 -> v8 #14359), updated for the new package name.

  • resolveDefaultExport.ts (existing, not changed in this PR): The iterative unwrapping approach with a maxDepth limit is a safe, bounded strategy that avoids walking arbitrary object graphs.

  • resolveDefaultExport.test.ts: Comprehensive test coverage including CommonJS interop shapes (no wrapper, single/double/triple nested), depth limiting, and edge cases (null, undefined, primitives, arrays, objects without default). Tests follow Vitest conventions and the project's test guide.

  • Import paths use the ~lib/ alias consistently across all consuming files.

No issues identified with code structure or maintainability.

Test Coverage

Unit tests:

  • The new resolveDefaultExport.test.ts provides thorough coverage of the generic unwrapping utility with 14 test cases across three describe blocks.
  • Existing tests in Json.test.tsx and JsonViewer.test.tsx implicitly validate that the compat shim correctly resolves the component (these tests render the Json components and assert on output).

E2E tests:

  • No new E2E tests are needed. This is a build-infrastructure fix that does not change any user-facing behavior — the Json component functionality remains identical.

Test coverage is adequate for these changes.

Backwards Compatibility

No breaking changes. This PR restores a pattern that was previously in place (from the Vite 8 upgrade) and only redirects imports through an internal shim. The public API and component behavior are unchanged. The type re-exports (OnCopyProps, OnSelectProps) maintain the same API surface for consuming files.

Security & Risk

No security concerns:

  • No new dependencies introduced — @microlink/react-json-view was already added in [chore] Migrate from unmaintained react-json-view to @microlink/react-json-view #14380.
  • No changes to server endpoints, authentication, file handling, or any security-sensitive code.
  • The resolveDefaultExport utility is bounded by maxDepth (default 3), preventing unbounded object traversal.
  • This is a low-risk change that restores a known-working pattern.

Regression risk: Low. The change only affects how the @microlink/react-json-view module is imported at the module boundary level. The existing unit tests and E2E tests for Json elements validate that rendering behavior is preserved.

External test recommendation

  • Recommend external_test: No
  • Triggered categories: None
  • Evidence:
    • All changes are confined to frontend module import paths (reactJsonViewCompat.ts, Json.tsx, useJsonTooltip.ts, JsonViewer.tsx)
    • No routing, auth, WebSocket, embedding, asset serving, cross-origin, storage, or security header changes
    • Pure build-infrastructure compatibility fix with no behavioral change
  • Suggested external_test focus areas: N/A
  • Confidence: High
  • Assumptions and gaps: None — the change scope is narrow and fully contained in frontend import plumbing.

Accessibility

No accessibility impact. The rendered Json components are unchanged — only the internal import path for the ReactJson component is modified.

Recommendations

No blocking issues. Minor observations:

  1. Consider adding a brief comment in the test file linking it to the compat shim that motivated the tests, e.g., a reference to reactJsonViewCompat.ts as the primary consumer of resolveDefaultExport. This would help future developers understand why this utility has dedicated tests.

  2. The resolveDefaultExport function's early-exit on falsy resolvedValue (line 31 of resolveDefaultExport.ts) means a module with { default: 0 } or { default: "" } would not unwrap the default. This is fine for the current use case (React components are always truthy), but if the utility is ever used for non-component exports, this edge case could be surprising. A brief JSDoc note about this assumption would be helpful.

Verdict

APPROVED: Clean, well-documented restoration of a necessary Vite 8 CommonJS compatibility shim for @microlink/react-json-view, with good test coverage added for the underlying utility. No breaking changes, no security concerns, and low regression risk.


This is an automated AI review by opus-4.6-thinking.

@lukasmasuch lukasmasuch merged commit b0ff1e7 into develop Mar 17, 2026
56 checks passed
@lukasmasuch lukasmasuch deleted the lukasmasuch/restore-json-compat branch March 17, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants