Skip to content

[CRA] Configure create-instant-app for self-hosted backends - #2803

Merged
nezaj merged 2 commits into
mainfrom
update-cra-self-host
Jul 30, 2026
Merged

[CRA] Configure create-instant-app for self-hosted backends#2803
nezaj merged 2 commits into
mainfrom
update-cra-self-host

Conversation

@nezaj

@nezaj nezaj commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

This PR does two things

  1. Make create-instant-app less of a schlep for self-hosted apps
  2. Centralize our logic for project bases -- there was a bit of duplication and making this template update work would have required copying things around again so figured was a good time to centralize

Self-hosting

Previously, INSTANT_CLI_API_URI pointed create-instant-app at a self-hosted backend, but generated apps still required manually adding apiURI and websocketURI to init.

Generated apps now include the self-hosted API and derived WebSocket configuration automatically.

Project bases

Consolidated duplicated project base declarations into one registry. CLI choices, environment variables, bundled templates, and backend configuration files now derive from the same source.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Project base metadata is centralized and reused for CLI choices, environment files, bundled examples, and backend configuration. The CLI injects API and WebSocket settings into scaffolded JavaScript, TypeScript, or Python backends when INSTANT_CLI_API_URI is set.

Changes

Project base configuration

Layer / File(s) Summary
Centralize project base metadata
client/packages/create-instant-app/src/projectBase.ts, client/packages/create-instant-app/src/cli.ts, client/packages/create-instant-app/src/env.ts, client/packages/create-instant-app/src/utils/getUserPkgManager.ts, client/packages/create-instant-app/scripts/copyExamples.ts, client/packages/version/src/version.ts
Project base definitions now provide shared backend configuration, environment names, CLI choices, type aliases, package-manager typing, bundled example selection, and version v1.0.54.
Inject backend configuration
client/packages/create-instant-app/src/backendConfig.ts
API URIs are converted to runtime WebSocket URIs and inserted into configured JavaScript, TypeScript, or Python scaffold files.
Wire startup configuration and validation
client/packages/create-instant-app/src/index.ts, client/packages/create-instant-app/src/backendConfig.test.ts
Startup applies backend configuration when INSTANT_CLI_API_URI is present, while tests cover URI conversion, scaffold updates, errors, and template metadata.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant applyBackendConfig
  participant projectBaseConfig
  participant ScaffoldFiles
  CLI->>applyBackendConfig: pass project base, project directory, and API URI
  applyBackendConfig->>projectBaseConfig: read configured backend files
  applyBackendConfig->>ScaffoldFiles: inject API and WebSocket configuration
  ScaffoldFiles-->>CLI: persist updated scaffold files
Loading

Possibly related PRs

Suggested reviewers: stopachka, drew-harris, dwwoelfel

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: configuring create-instant-app for self-hosted backends.
Description check ✅ Passed The description matches the changeset, covering self-hosted backend setup and centralized project base configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 update-cra-self-host

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.

@github-actions

Copy link
Copy Markdown
Contributor

View Vercel preview at instant-www-js-update-cra-self-host-jsv.vercel.app.

@drew-harris drew-harris 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.

@nezaj
nezaj force-pushed the update-cra-self-host branch from ccf9bdc to c73d2e2 Compare July 30, 2026 20:03
@nezaj
nezaj merged commit 72b2ee5 into main Jul 30, 2026
26 of 27 checks passed
@nezaj
nezaj deleted the update-cra-self-host branch July 30, 2026 20:05

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@client/packages/create-instant-app/src/index.ts`:
- Around line 48-54: Wrap the applyBackendConfig call guarded by
INSTANT_CLI_API_URI in error handling, catching malformed URI or
template-initializer failures. Surface a concise, user-facing error through the
existing CLI error mechanism, avoid the raw stack trace, and stop the scaffold
flow before continuing with subsequent setup steps.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 56ed13f9-863a-449b-9c6c-02fcf136ef5f

📥 Commits

Reviewing files that changed from the base of the PR and between ccf9bdc and c73d2e2.

📒 Files selected for processing (9)
  • client/packages/create-instant-app/scripts/copyExamples.ts
  • client/packages/create-instant-app/src/backendConfig.test.ts
  • client/packages/create-instant-app/src/backendConfig.ts
  • client/packages/create-instant-app/src/cli.ts
  • client/packages/create-instant-app/src/env.ts
  • client/packages/create-instant-app/src/index.ts
  • client/packages/create-instant-app/src/projectBase.ts
  • client/packages/create-instant-app/src/utils/getUserPkgManager.ts
  • client/packages/version/src/version.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/packages/create-instant-app/src/utils/getUserPkgManager.ts

Comment on lines +48 to +54
if (process.env.INSTANT_CLI_API_URI) {
applyBackendConfig(
project.base,
projectDir,
process.env.INSTANT_CLI_API_URI,
);
}

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Uncaught applyBackendConfig failure crashes mid-scaffold, leaving a broken half-set-up project.

This call isn't wrapped in error handling. If INSTANT_CLI_API_URI is malformed, or a scaffolded file's expected initializer text (init({ / db = Instant()) doesn't match (e.g. future template drift), applyBackendConfig throws and the whole process dies with a raw stack trace — after projectDir already exists on disk but before rule files, env file, dependency install, package renaming, or git init have run.

🔧 Proposed fix: surface a clear, non-crashing error
   if (process.env.INSTANT_CLI_API_URI) {
-    applyBackendConfig(
-      project.base,
-      projectDir,
-      process.env.INSTANT_CLI_API_URI,
-    );
+    try {
+      applyBackendConfig(
+        project.base,
+        projectDir,
+        process.env.INSTANT_CLI_API_URI,
+      );
+    } catch (err) {
+      console.error(
+        `Warning: could not apply self-hosted backend config: ${
+          err instanceof Error ? err.message : err
+        }`,
+      );
+      console.error(
+        'You may need to manually set apiURI/websocketURI in your backend init.',
+      );
+    }
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (process.env.INSTANT_CLI_API_URI) {
applyBackendConfig(
project.base,
projectDir,
process.env.INSTANT_CLI_API_URI,
);
}
if (process.env.INSTANT_CLI_API_URI) {
try {
applyBackendConfig(
project.base,
projectDir,
process.env.INSTANT_CLI_API_URI,
);
} catch (err) {
console.error(
`Warning: could not apply self-hosted backend config: ${
err instanceof Error ? err.message : err
}`,
);
console.error(
'You may need to manually set apiURI/websocketURI in your backend init.',
);
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/packages/create-instant-app/src/index.ts` around lines 48 - 54, Wrap
the applyBackendConfig call guarded by INSTANT_CLI_API_URI in error handling,
catching malformed URI or template-initializer failures. Surface a concise,
user-facing error through the existing CLI error mechanism, avoid the raw stack
trace, and stop the scaffold flow before continuing with subsequent setup steps.

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.

2 participants