Skip to content

Fix docs demo React externalization and local dev workflow - #25

Merged
xinaesthete merged 4 commits into
mainfrom
codex/fix-ci-demo-require-error
Apr 14, 2026
Merged

Fix docs demo React externalization and local dev workflow#25
xinaesthete merged 4 commits into
mainfrom
codex/fix-ci-demo-require-error

Conversation

@xinaesthete

@xinaesthete xinaesthete commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • externalize react/jsx-runtime, react/jsx-dev-runtime, and zustand subpaths to avoid the demo bundle requiring React at runtime
  • broaden @spatialdata/vis externals to keep workspace package boundaries intact in docs and CI builds
  • update local dev scripts so docs and the vis demo bind to explicit localhost ports and vis rebuilds dist while the demo server runs

Testing

  • pnpm build
  • pnpm --filter docs build
  • pnpm dev

Summary by CodeRabbit

  • Chores

    • Development servers and demo tooling now bind explicitly to localhost with fixed ports for more predictable local testing.
    • Docs site config adjusted to improve local dev behavior.
  • Refactor

    • Dev tooling coordinated to run concurrent build/watch and demo servers with improved startup/shutdown handling.
    • Build tooling updated to treat additional dependencies and subpath imports as external for more consistent bundling.
  • Bug Fixes

    • Image/viewer loading, raster-source resolution, selection/stats, and metadata handling improved for more reliable previews and accurate metrics.

@coderabbitai

coderabbitai Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 80283237-b6d5-474c-ad69-435000465db0

📥 Commits

Reviewing files that changed from the base of the PR and between a6f2859 and fc3746a.

📒 Files selected for processing (1)
  • packages/avivatorish/src/utils.ts

📝 Walkthrough

Walkthrough

Dev/server scripts and Vite configs now bind dev servers to 127.0.0.1 and stricter ports; vis adds a coordinated dev script that spawns a build watcher and demo dev server. Library externals expanded to regexes. avivatorish adds raster-source resolution helpers and updates callers to use them. (45 words)

Changes

Cohort / File(s) Summary
Docs dev script & Docusaurus plugin
docs/package.json, docs/docusaurus.config.ts
docs dev script now uses --host 127.0.0.1. Docusaurus config imports Plugin, adds plugins: [disableDevSplitChunks], and defines disableDevSplitChunks() to disable splitChunks for non-production client builds.
Vis dev coordination & demo config
packages/vis/package.json, packages/vis/scripts/dev.mjs, packages/vis/vite.config.demo.ts
Replaced direct vite dev call with node scripts/dev.mjs; added dev:demo for starting demo server at 127.0.0.1:5173 --strictPort. New dev.mjs spawns a Vite build watcher and demo dev server, centralizes error/exit handling, maps signals, and performs coordinated shutdown; demo config sets host, port, strictPort, and open: false.
Vite externals (library builds)
packages/avivatorish/vite.config.ts, packages/vis/vite.config.ts, vite.config.base.ts
External lists changed to regexes to externalize package subpaths (^@spatialdata\/.*$, ^zustand(?:\/.*)?$); vite.config.base.ts also adds react/jsx-runtime and react/jsx-dev-runtime to externals.
Raster source resolution & stats logic
packages/avivatorish/src/utils.ts, packages/avivatorish/src/hooks.ts, packages/vis/src/ImageView/index.tsx
Added RasterSourceLike, isRasterSourceLike, resolveRasterSource, getRasterSource. Call sites updated to resolve raster sources (early-return when absent); stats/selection/bounding helpers now use resolved raster sources rather than indexing arrays directly.

Sequence Diagram

sequenceDiagram
    participant Parent as dev.mjs (Parent Process)
    participant ViteBuild as Vite Build (watch)
    participant ViteDemo as Vite Demo (dev server)
    participant System as System Signals (SIGINT/SIGTERM)

    Parent->>ViteBuild: spawn "pnpm vite build --watch"
    Parent->>ViteDemo: spawn "pnpm vite --config vite.config.demo.ts --host 127.0.0.1 --port 5173 --strictPort"
    
    ViteBuild-->>Parent: 'error' / 'exit' (non-zero)
    ViteDemo-->>Parent: 'error' / 'exit' (non-zero)
    Note over Parent: On first failure or non-successful exit\nset shuttingDown = true, kill children
    
    alt System signal received
        System->>Parent: SIGINT / SIGTERM
        Parent->>Parent: map to exit code (130 / 143), set shuttingDown = true
        Parent->>ViteBuild: kill()
        Parent->>ViteDemo: kill()
    end

    Parent->>Parent: wait 500ms
    Parent->>System: process.exit(code)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through configs, bindings, and build,
Spawned two processes, all tidy and skilled.
Regex nets catch subpaths that flee,
Raster roots found — then stats run with glee.
Hoppity-hop, the dev server’s chilled!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objectives: fixing React externalization for the docs demo and improving the local dev workflow with updated scripts and localhost bindings.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-ci-demo-require-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/avivatorish/src/hooks.ts (2)

56-57: Consider consolidating state updates.

Lines 56-57 make two separate viewerStore.setState calls in sequence. These could be merged into a single call for clarity and minor performance benefit:

♻️ Proposed consolidation
-            viewerStore.setState({ isChannelLoading: [true] });
-            viewerStore.setState({ isViewerLoading: true, metadata: null });
+            viewerStore.setState({ isChannelLoading: [true], isViewerLoading: true, metadata: null });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/avivatorish/src/hooks.ts` around lines 56 - 57, The two sequential
state updates should be consolidated into one setState call: replace the
separate viewerStore.setState({ isChannelLoading: [true] }) and
viewerStore.setState({ isViewerLoading: true, metadata: null }) with a single
viewerStore.setState that sets isChannelLoading, isViewerLoading, and metadata
together (i.e., viewerStore.setState({ isChannelLoading: [true],
isViewerLoading: true, metadata: null })) to avoid redundant updates and
potential extra re-renders.

113-116: Silent early return may hide loader resolution failures.

When resolveRasterSource returns undefined, the function silently exits without updating the loading state or notifying the user. The viewer may remain in a stale or loading state indefinitely.

Consider logging a warning or setting an error state:

🔊 Proposed fix to add warning
             const rasterSource = resolveRasterSource(loader);
             if (!rasterSource) {
+                console.warn("Unable to resolve raster source from loader; skipping settings update");
+                viewerStore.setState({ isViewerLoading: false });
                 return;
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/avivatorish/src/hooks.ts` around lines 113 - 116, The early return
after calling resolveRasterSource(loader) silently hides failures; instead of
just returning, update the component/viewer state and surface a warning: when
rasterSource is falsy, call the appropriate state setters (e.g.,
setLoading(false) and setError(...) or dispatch an error action) and emit a
warning (e.g., processLogger.warn or console.warn) mentioning the loader and
that resolveRasterSource failed so consumers aren’t left in a stale loading
state; update the block that currently reads "const rasterSource =
resolveRasterSource(loader); if (!rasterSource) { return; }" to perform these
logging/state updates before returning.
packages/avivatorish/src/utils.ts (1)

408-416: Type guard does not verify labels and shape are arrays.

isRasterSourceLike checks that labels and shape properties exist, but doesn't verify they are arrays. If a malformed loader has labels: "foo" or shape: 42, downstream code calling labels.length or iterating over shape could fail unexpectedly.

Consider strengthening the guard:

🛡️ Proposed fix to validate array types
 export function isRasterSourceLike(value: unknown): value is RasterSourceLike {
     if (!value || typeof value !== "object") return false;
-    return "getRaster" in value && typeof value.getRaster === "function" && "labels" in value && "shape" in value;
+    return (
+        "getRaster" in value &&
+        typeof value.getRaster === "function" &&
+        "labels" in value &&
+        Array.isArray(value.labels) &&
+        "shape" in value &&
+        Array.isArray(value.shape)
+    );
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/avivatorish/src/utils.ts` around lines 408 - 416, The type guard
isRasterSourceLike currently only checks existence of labels and shape but not
that they are arrays; update isRasterSourceLike to additionally verify
Array.isArray(value.labels) and Array.isArray(value.shape) and also that
value.labels.every(item => typeof item === "string") and value.shape.every(item
=> typeof item === "number") while retaining the existing check that
value.getRaster is a function (reference symbols: isRasterSourceLike,
RasterSourceLike, getRaster, labels, shape) so downstream code can safely use
labels.length and iterate shape.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/avivatorish/src/utils.ts`:
- Around line 580-582: getBoundingCube calls getPhysicalSizeScalingMatrix with
`source` (a RasterSourceLike) which lacks `meta.physicalSizes`, so scaling falls
back to identity; change the argument to the original `loader` (PixelSource) so
getPhysicalSizeScalingMatrix can read `meta.physicalSizes` and return the
correct scaling matrix — update the call in getBoundingCube from using `source`
to using `loader`.

---

Nitpick comments:
In `@packages/avivatorish/src/hooks.ts`:
- Around line 56-57: The two sequential state updates should be consolidated
into one setState call: replace the separate viewerStore.setState({
isChannelLoading: [true] }) and viewerStore.setState({ isViewerLoading: true,
metadata: null }) with a single viewerStore.setState that sets isChannelLoading,
isViewerLoading, and metadata together (i.e., viewerStore.setState({
isChannelLoading: [true], isViewerLoading: true, metadata: null })) to avoid
redundant updates and potential extra re-renders.
- Around line 113-116: The early return after calling
resolveRasterSource(loader) silently hides failures; instead of just returning,
update the component/viewer state and surface a warning: when rasterSource is
falsy, call the appropriate state setters (e.g., setLoading(false) and
setError(...) or dispatch an error action) and emit a warning (e.g.,
processLogger.warn or console.warn) mentioning the loader and that
resolveRasterSource failed so consumers aren’t left in a stale loading state;
update the block that currently reads "const rasterSource =
resolveRasterSource(loader); if (!rasterSource) { return; }" to perform these
logging/state updates before returning.

In `@packages/avivatorish/src/utils.ts`:
- Around line 408-416: The type guard isRasterSourceLike currently only checks
existence of labels and shape but not that they are arrays; update
isRasterSourceLike to additionally verify Array.isArray(value.labels) and
Array.isArray(value.shape) and also that value.labels.every(item => typeof item
=== "string") and value.shape.every(item => typeof item === "number") while
retaining the existing check that value.getRaster is a function (reference
symbols: isRasterSourceLike, RasterSourceLike, getRaster, labels, shape) so
downstream code can safely use labels.length and iterate shape.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d6c3ec21-40b4-4169-9f22-13b2f59f4150

📥 Commits

Reviewing files that changed from the base of the PR and between 68210f5 and a6f2859.

📒 Files selected for processing (4)
  • docs/docusaurus.config.ts
  • packages/avivatorish/src/hooks.ts
  • packages/avivatorish/src/utils.ts
  • packages/vis/src/ImageView/index.tsx

Comment thread packages/avivatorish/src/utils.ts
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