Skip to content

docs: create itdoc playground pages on official documentation#254

Merged
PENEKhun merged 23 commits intodevelopfrom
docs/playground
Oct 8, 2025
Merged

docs: create itdoc playground pages on official documentation#254
PENEKhun merged 23 commits intodevelopfrom
docs/playground

Conversation

@PENEKhun
Copy link
Copy Markdown
Member

@PENEKhun PENEKhun commented Oct 4, 2025

Changes

사진과 실제 화면이 상이할 수 있으니 직접 실행해보세요

  • how to access playground pages?

    image
  • loading playground

    image
  • After loading

image

you can change app.js and app.test.js code in this page.

  • after run
aa.mov

You can run itdoc test code directly in the browser and see the results there.

How to test for reviewer

  1. clone this branches

  2. run

pnpm --filter itdoc-doc start
  1. access localhost:3000

closed #244

Summary by CodeRabbit

  • New Features

    • Added an in-browser Playground to edit, run, and test example apps, generate OpenAPI output, and preview Swagger/Redoc; includes a dedicated Playground page and navbar/homepage access.
  • UI/Style

    • Added comprehensive Playground UI styles (editor, terminal, modals, install/progress overlays) and updated homepage button layout.
  • Localization

    • Added Korean translation for the Playground navbar label.
  • Chores

    • Improved tooling and runtime support and updated dependencies to enable the Playground and runtime behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 4, 2025

Walkthrough

Adds an interactive Playground to the docs site. Docusaurus config receives two server-only plugins: webcontainer-alias (aliases @webcontainer/api to an SSR stub) and webcontainer-local-itdoc (rebuilds and caches a local itdoc tarball under static/playground). Introduces a browser-only React Playground component (CodeMirror editor, XTerm terminal, WebContainer orchestration, dependency install, test execution, and OpenAPI generation/preview) with CSS modules, a Playground page, navbar/home link updates, and a Korean i18n entry. Adds a server-side WebContainer SSR stub, runtime-aware testContext using @webcontainer/env, dependency/script updates, script/clean.mjs, and static/playground/.gitignore.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The PR delivers an interactive in-browser playground with code editing, test execution, and OpenAPI preview that addresses most objectives of issue #244 but does not include the ability to generate or share persistent playground state links as requested. To fully satisfy issue #244, add functionality for generating and sharing playground state links or update the issue to defer shareable link support to a subsequent iteration.
Out of Scope Changes Check ⚠️ Warning The inclusion of a standalone clean script (script/clean.mjs) and the corresponding package.json clean script modification is unrelated to embedding an interactive playground and appears to be general build tooling not required for the documentation feature. Move the clean.mjs script and the package.json clean script change into a separate housekeeping PR to keep the playground feature focused and isolated.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary addition of interactive playground pages to the official documentation and aligns with the main content of the changeset, making it clear to collaborators what this PR introduces.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/playground

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 658cf1b and b861994.

📒 Files selected for processing (1)
  • itdoc-doc/src/components/Playground/styles.module.css (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • itdoc-doc/src/components/Playground/styles.module.css

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.

@PENEKhun PENEKhun self-assigned this Oct 4, 2025
@PENEKhun PENEKhun marked this pull request as ready for review October 4, 2025 16:06
@PENEKhun PENEKhun requested review from json-choi and wnghdcjfe and removed request for wnghdcjfe October 4, 2025 16:06
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (3)
script/clean.mjs (2)

22-31: Clean script is safe but could benefit from directory validation.

The implementation correctly uses native fs/promises.rm with force: true (no error if missing) and recursive: true for nested directories. Error handling is appropriate.

Consider adding a safety check to verify the script is running from the expected repository root:

 async function main() {
+    // Verify we're in the correct directory
+    const packageJsonPath = resolve(process.cwd(), "package.json")
+    try {
+        await fs.access(packageJsonPath)
+    } catch {
+        console.error("[clean] Must run from repository root (package.json not found)")
+        process.exitCode = 1
+        return
+    }
+
     const target = resolve(process.cwd(), "build")

This prevents accidental deletion if the script is invoked from an unexpected location.


18-18: Narrow the ESLint disable comment.

The broad /* eslint-disable */ disables all rules. Consider using more specific disables if only certain rules need to be suppressed, or remove it entirely if no violations exist.

-/* eslint-disable */

Then run ESLint to see if any specific rules need to be disabled.

itdoc-doc/src/pages/playground.module.css (1)

96-96: Provide a CSS fallback or tighten your browserslist for color-mix() support
Your production targets (>0.5%, not dead) include Safari versions below 16.2, which don’t support color-mix(). To prevent missing backgrounds, add a fallback before your mix—for example:

background-color: var(--ifm-color-emphasis-200);
background-color: color-mix(in srgb, var(--ifm-color-emphasis-200) 60%, transparent);

—or restrict your browserslist to Safari >= 16.2.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0acfa8f and 7ad9a42.

⛔ Files ignored due to path filters (2)
  • itdoc-doc/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • itdoc-doc/docusaurus.config.ts (4 hunks)
  • itdoc-doc/i18n/ko/docusaurus-theme-classic/navbar.json (1 hunks)
  • itdoc-doc/package.json (1 hunks)
  • itdoc-doc/src/components/Playground/index.tsx (1 hunks)
  • itdoc-doc/src/components/Playground/styles.module.css (1 hunks)
  • itdoc-doc/src/components/Playground/webcontainerStub.ts (1 hunks)
  • itdoc-doc/src/pages/index.module.css (1 hunks)
  • itdoc-doc/src/pages/index.tsx (1 hunks)
  • itdoc-doc/src/pages/playground.module.css (1 hunks)
  • itdoc-doc/src/pages/playground.tsx (1 hunks)
  • itdoc-doc/static/playground/.gitignore (1 hunks)
  • lib/dsl/interface/testContext.ts (1 hunks)
  • package.json (2 hunks)
  • script/clean.mjs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
lib/dsl/interface/testContext.ts (1)
lib/dsl/interface/itDoc.ts (2)
  • testContext (37-47)
  • description (21-48)
🔇 Additional comments (8)
itdoc-doc/package.json (1)

23-32: LGTM! Dependencies align with Playground requirements.

The added dependencies appropriately support the interactive Playground feature:

  • CodeMirror packages for the in-browser editor
  • WebContainer API (v1.6.1) for the browser-based Node.js runtime
  • XTerm packages for terminal emulation

The caret version ranges follow standard npm practices for automatic minor/patch updates.

lib/dsl/interface/testContext.ts (2)

20-26: Runtime detection pattern is safe.

The IIFE with try-catch ensures graceful fallback if @webcontainer/env is unavailable or if isWebContainer() throws.


38-64: No action required: testContext.get() null case is handled
ResponseBuilder coalesces testContext.get() to an empty string (testContext.get() || "").

itdoc-doc/src/pages/index.tsx (1)

24-26: LGTM! Playground button follows existing patterns.

The implementation mirrors the existing "Introduce itdoc" button pattern and correctly uses Docusaurus Link for client-side routing to the new /playground route.

itdoc-doc/static/playground/.gitignore (1)

1-1: LGTM! Appropriately excludes generated tarball.

The packaged itdoc.tgz is a build artifact and should not be committed. This aligns with the Playground packaging workflow that generates the tarball at build time.

itdoc-doc/src/pages/index.module.css (2)

27-41: LGTM! Playground button styling follows Docusaurus theming.

The .playgroundButton class appropriately uses Docusaurus CSS custom properties for consistent theming across light/dark modes. Hover and focus states are properly defined for accessibility.


19-25: .buttons usage limited to homepage

Search shows .buttons is only referenced in src/pages/index.tsx, so the new column layout affects only the homepage and poses no wider impact.

itdoc-doc/i18n/ko/docusaurus-theme-classic/navbar.json (1)

18-21: Approve Korean Playground translation: Default label exists in docusaurus.config.ts and the translation follows the established pattern.

@PENEKhun PENEKhun added the Documentation Something isn't working label Oct 5, 2025
@PENEKhun PENEKhun marked this pull request as draft October 5, 2025 12:11
@PENEKhun PENEKhun marked this pull request as ready for review October 5, 2025 12:15
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
itdoc-doc/src/components/Playground/styles.module.css (1)

420-432: Past review concern has been resolved.

The display: grid declaration is now present on line 424, so the run modal will correctly display the terminal beside the generated docs in a grid layout.

🧹 Nitpick comments (3)
itdoc-doc/src/components/Playground/styles.module.css (2)

353-353: Use more reasonable z-index values.

The z-index values of 9999999999 (line 353) and 999999999999 (line 988) are unnecessarily high. Consider using more maintainable values in a lower range (e.g., 1000-2000) or establishing a z-index scale via CSS variables to keep stacking contexts manageable across the codebase.

Apply this diff to use more reasonable values:

 .runModalBackdrop {
     position: fixed;
     inset: 0;
     background: rgba(15, 23, 42, 0.65);
     display: flex;
     align-items: center;
     justify-content: center;
     padding: clamp(1.5rem, 4vw, 2.5rem);
-    z-index: 9999999999;
+    z-index: 1000;
 }
 .previewModalBackdrop {
     position: fixed;
     inset: 0;
     background: rgba(15, 23, 42, 0.78);
     backdrop-filter: blur(4px);
     display: flex;
     justify-content: center;
     align-items: center;
     padding: clamp(2rem, 6vw, 4rem);
-    z-index: 999999999999;
+    z-index: 1100;
 }

Also applies to: 988-988


828-828: Provide fallback or @supports guard for color-mix()
color-mix() is supported from Chrome/Edge 111+, Firefox 113+, Safari/iOS 16.2+, Opera 97+, Samsung Internet 22+—wrap the usages on lines 828 and 870 in an @supports(color-mix()) check or supply a fallback color for older browsers.

itdoc-doc/src/components/Playground/index.tsx (1)

336-1256: Consider splitting this large component for improved maintainability.

The Playground component is comprehensive (1258 lines) and handles many concerns: WebContainer orchestration, terminal output, code editors, install progress, run modal, and preview modal. While the current implementation is functional, splitting it into smaller, focused components would improve maintainability and testability.

Consider extracting sub-components such as:

  • PlaygroundTerminal - Terminal display and management
  • PlaygroundEditor - CodeMirror editor wrapper
  • InstallProgressOverlay - Installation progress UI
  • RunResultsModal - Test run output modal
  • SwaggerPreviewModal - OpenAPI preview modal

This would reduce the cognitive load and make each piece easier to reason about independently.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ad9a42 and e728534.

📒 Files selected for processing (3)
  • itdoc-doc/src/components/Playground/index.tsx (1 hunks)
  • itdoc-doc/src/components/Playground/styles.module.css (1 hunks)
  • package.json (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
itdoc-doc/src/components/Playground/index.tsx (1)
script/makedocs/index.ts (1)
  • generateDocs (29-75)
🔇 Additional comments (4)
itdoc-doc/src/components/Playground/index.tsx (4)

1096-1103: Verify the empty Swagger Preview placeholder is intentional.

The "Swagger Preview" section in the run modal renders an empty placeholder (lines 1096-1102). The actual Redoc preview only appears in the fullscreen modal. If this is intentional to encourage users to click "Fullscreen preview," consider adding a hint message in this placeholder area. Otherwise, if an inline preview is desired here, you'll need to render a second Redoc instance.

Is the empty inline preview placeholder intentional, or should this section render a compact Redoc preview similar to the fullscreen modal?


507-608: LGTM: Robust WebContainer setup and provisioning.

The WebContainer initialization effect handles multiple concerns well:

  • Proper cancellation pattern to prevent memory leaks
  • Graceful fallback from local tarball to npm registry
  • Clear error messages with cross-origin isolation hints
  • Appropriate cleanup on unmount

The implementation is comprehensive and handles edge cases effectively.


433-505: LGTM: Solid terminal integration with proper lifecycle management.

The terminal setup effect demonstrates good practices:

  • Defers initialization until the modal is visible
  • Handles pending output chunks before terminal is ready
  • Uses ResizeObserver and window resize events for responsive fitting
  • Proper cleanup and disposal on unmount
  • Try-catch blocks prevent fit() errors from breaking the UI

802-847: LGTM: Well-structured test execution flow.

The handleRun function handles the test execution lifecycle effectively:

  • Writes updated code to the WebContainer filesystem
  • Pipes process output to the terminal
  • Uses retry logic to handle eventual consistency of generated files
  • Provides clear, actionable error messages for different failure scenarios
  • Proper state management throughout the async flow

Copy link
Copy Markdown
Collaborator

@wnghdcjfe wnghdcjfe left a comment

Choose a reason for hiding this comment

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

I think almost all the codes are good.
However, the swagger privacy does not appear. Please check it.

2025-10-07.11-00-04.mp4

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
itdoc-doc/docusaurus.config.ts (1)

69-74: Consider simplifying or documenting the cache invalidation logic.

The buildDir mtime check on line 74 is somewhat redundant since the plugin always runs pnpm run build when repacking (line 85). The check will only trigger if an external build was run between doc builds, but then the plugin rebuilds anyway.

This conservative approach works correctly but could be simplified to just check if the tarball exists (unless you want to detect external builds to avoid redundant rebuilds).

Consider either:

  1. Removing the buildDir mtime check and relying on the force flag for cache invalidation:
 const shouldRepack =
     forceRepack ||
-    !fs.existsSync(targetTarball) ||
-    !fs.existsSync(buildDir) ||
-    fs.statSync(buildDir).mtimeMs > fs.statSync(targetTarball).mtimeMs
+    !fs.existsSync(targetTarball)
  1. Or adding a comment explaining the reasoning:
// Repack if: forced, tarball missing, or buildDir was externally rebuilt
const shouldRepack = ...
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7eda08 and 100f14e.

📒 Files selected for processing (1)
  • itdoc-doc/docusaurus.config.ts (4 hunks)
🔇 Additional comments (4)
itdoc-doc/docusaurus.config.ts (4)

4-7: LGTM! Server-side imports are appropriate.

The Node.js module imports (fs, path, os, execFileSync) are correctly added to support the server-side plugin operations below.


39-57: LGTM! SSR alias plugin is correctly implemented.

The webcontainerAliasPlugin correctly stubs out the WebContainer API for server-side rendering by aliasing it only when isServer is true. This prevents SSR build failures for browser-only APIs.


58-122: LGTM! Plugin correctly builds and packages itdoc for the playground.

The webcontainerLocalItdocPlugin implementation is solid:

  • Proper error handling with try/finally cleanup
  • Safe command execution using execFileSync
  • Windows compatibility addressed with shell: true option (lines 88, 96)
  • Careful parsing of pnpm output with null checks
  • Conservative caching approach that favors correctness

165-165: LGTM! Playground navbar link is correctly added.

The navbar item follows standard Docusaurus configuration and integrates properly with the new playground feature.

@PENEKhun
Copy link
Copy Markdown
Member Author

PENEKhun commented Oct 7, 2025

I think almost all the codes are good. However, the swagger privacy does not appear. Please check it.

2025-10-07.11-00-04.mp4

sorry my mistake!

image

i remove that section. check it please

@PENEKhun PENEKhun requested a review from wnghdcjfe October 7, 2025 12:59
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (1)
itdoc-doc/src/components/Playground/index.tsx (1)

1211-1246: A11y: same focus management for the Swagger Preview modal.

Mirror the focus trap / initial focus / ESC / restore focus pattern here.

🧹 Nitpick comments (2)
itdoc-doc/src/components/Playground/index.tsx (2)

999-1019: A11y: add modal focus trap, initial focus, ESC to close, and restore focus.

Improve keyboard UX/compliance: set initial focus to Close, trap focus within modal, close on Escape, and restore focus to the Run button on exit.

Example (add alongside existing state/effects):

// refs
const runButtonRef = useRef<HTMLButtonElement|null>(null)
const runCloseRef = useRef<HTMLButtonElement|null>(null)

// set ref on the Run button and Close button
// <button ref={runButtonRef} ...>Run</button>
// <button ref={runCloseRef} ...>Close</button>

useEffect(() => {
  if (!showRunModal) return
  const prev = document.activeElement as HTMLElement | null
  runCloseRef.current?.focus()

  const onKeyDown = (e: KeyboardEvent) => {
    if (e.key === "Escape") setShowRunModal(false)
  }
  window.addEventListener("keydown", onKeyDown)

  return () => {
    window.removeEventListener("keydown", onKeyDown)
    ;(prev ?? runButtonRef.current)?.focus()
  }
}, [showRunModal])

// Optional: implement a simple focus trap by cycling Tab focus within the modal.

398-407: Pin Redoc CDN to v2.5.0 and add SRI or self-host
Replace the REDOC_CDN_URL alias with the exact v2.5.0 URL (e.g. https://cdn.jsdelivr.net/npm/redoc@2.5.0/bundles/redoc.standalone.js), compute and include the integrity hash per jsDelivr SRI guidelines, or vend the bundle under /static to eliminate supply-chain risk.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 100f14e and 658cf1b.

📒 Files selected for processing (1)
  • itdoc-doc/src/components/Playground/index.tsx (1 hunks)

@PENEKhun
Copy link
Copy Markdown
Member Author

PENEKhun commented Oct 7, 2025

@wnghdcjfe

I found an additional bug where the API description in the Swagger preview was not visible because both the background and the font were white.

I fixed it through b861994

AS-IS

image

TO-BE

image

Copy link
Copy Markdown
Collaborator

@wnghdcjfe wnghdcjfe left a comment

Choose a reason for hiding this comment

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

LGTM

@PENEKhun PENEKhun merged commit 9899c3a into develop Oct 8, 2025
2 checks passed
@PENEKhun PENEKhun deleted the docs/playground branch October 8, 2025 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs]: Add Interactive Playground to itdoc.kr Documentation

2 participants