Skip to content

Conversation

@taj54
Copy link
Member

@taj54 taj54 commented Aug 10, 2025

Summary by CodeRabbit

  • New Features

    • Added support for passing interactive quiz cues to the video component.
    • Migrated build configuration to a TypeScript-based setup.
    • Introduced a React wrapper with an example for easier integration.
  • Bug Fixes

    • Fixed a race condition during initialization.
  • Style

    • Enforced consistent LF line endings in code formatting.
  • Chores

    • Enabled code, commit, and test linting.
    • Updated package metadata, dependencies, and established project structure with CI workflows.
  • Documentation

    • Added CONTRIBUTING and DEVELOPER guides.
    • Enhanced README with detailed project information.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

Walkthrough

This update introduces explicit LF line endings in Prettier configuration, adds a changelog entry for version 0.0.2, updates the example to use an external package and provide quiz cues, refactors the player initialization and cue/translation loading logic in the main component, and migrates the tsup build config to a functional form with dynamic output extension handling.

Changes

Cohort / File(s) Change Summary
Prettier Configuration
.prettierrc
Added "endOfLine": "lf" to enforce LF line endings.
Changelog Update
CHANGELOG.md
Added entry for version 0.0.2, documenting style, chore, test, documentation, feature, and bug fix updates.
Example Usage Update
examples/index.tsx
Changed InteractiveVideo import to external package; added cues prop with a quiz interaction.
Player Initialization Refactor
src/index.tsx
Refactored IVLabsPlayer initialization: removed setTimeout, modularized cue/translation loading into separate effects, consolidated event listener registration.
Build Config Refactor
tsup.config.ts
Changed config export to a function for dynamic options; added output extension customization and license annotation.

Sequence Diagram(s)

sequenceDiagram
    participant App as React App
    participant IV as InteractiveVideo Component
    participant Player as IVLabsPlayer

    App->>IV: Render with props (cues, translations)
    IV->>Player: Initialize player if container exists
    IV->>Player: Register event listeners
    IV->>Player: Load cues (on cues prop change)
    IV->>Player: Load translations (on translations prop change)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

A bunny with code on its mind,
Hopped through configs, tidy and kind.
With cues for a quiz, and lines set to LF,
The player refactored, now better than ever left.
Changelog in tow, and a license to show—
This release is ready, let the features flow! 🐇✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@taj54 taj54 self-assigned this Aug 10, 2025
@taj54 taj54 merged commit 621a7c9 into interactive-video-labs:main Aug 10, 2025
1 check passed
Copy link
Contributor

@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: 5

🧹 Nitpick comments (2)
examples/index.tsx (1)

16-26: Validate cue shape against core CuePoint type.

The cue uses a payload with { type: 'quiz', ... } and omits a top-level type. If CuePoint expects a top-level type, this may be rejected at runtime.

If needed, adjust to match the expected shape (e.g., add type at the top level) per @interactive-video-labs/core’s type:

{
  id: 'cue1',
  time: 2,
  // type: 'quiz', // if required at top-level
  payload: { type: 'quiz', question: '...', answers: [...] }
}

Tip: In real browsers, autoplay often requires muted to be true to avoid being blocked; consider adding it in the example for a smoother OOTB run.

CHANGELOG.md (1)

15-16: Fix typos and polish phrasing.

  • “confugured” → “configured”
  • Consider capitalizing “LF” for consistency.
- - Tsup config file confugured
+ - Tsup config file configured
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 546394c and f8fe036.

📒 Files selected for processing (5)
  • .prettierrc (1 hunks)
  • CHANGELOG.md (1 hunks)
  • examples/index.tsx (2 hunks)
  • src/index.tsx (2 hunks)
  • tsup.config.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/index.tsx (1)
test/InteractiveVideo.test.tsx (5)
  • videoSrc (34-85)
  • IVLabsPlayer (13-20)
  • loadCues (14-19)
  • beforeEach (22-93)
  • render (87-92)
🔇 Additional comments (1)
examples/index.tsx (1)

3-3: Example import from published package looks good.

This aligns the example with the external package entry point and validates the public API surface.

Comment on lines +5 to +6
"singleQuote": true,
"endOfLine": "lf"
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Enforce LF consistently across OS (add .gitattributes).

Prettier will rewrite files to LF on save, but Git checkouts on Windows can still introduce CRLF. Add a repo-level .gitattributes to avoid churn.

Suggested .gitattributes:

* text=auto eol=lf

# binary files
*.png -text
*.jpg -text
*.jpeg -text
*.gif -text
*.pdf -text

Verification script to confirm presence/config:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
if fd -t f ".gitattributes" >/dev/null; then
  echo ".gitattributes found"; echo
  fd -t f ".gitattributes" -x sh -c 'echo "== {} =="; cat {}'
else
  echo "Missing .gitattributes at repo root"
  exit 1
fi

Length of output: 163


Enforce LF line endings via .gitattributes

The .gitattributes file exists at the repo root but is currently empty. To avoid CRLF churn on Windows checkouts, please add the following content:

Files needing update:

  • .gitattributes (repo root)

Suggested diff:

--- .gitattributes
+++ .gitattributes
+* text=auto eol=lf
+
+# binary files
+*.png   -text
+*.jpg   -text
+*.jpeg  -text
+*.gif   -text
+*.pdf   -text
🤖 Prompt for AI Agents
In the .prettierrc file at lines 5 to 6, the review suggests enforcing LF line
endings via the .gitattributes file. To fix this, create or update the
.gitattributes file at the repository root by adding configuration that enforces
LF line endings for all relevant files, preventing CRLF line ending issues on
Windows checkouts.

Comment on lines +62 to 72
if (!containerRef.current) return;

try {
setTimeout(() => {
if (containerRef.current) {
const player = new IVLabsPlayer(uniqueIdRef.current, playerConfig);
playerRef.current = player;

if (onAnalyticsEvent) {
player.on('PLAYER_LOADED', (payload?: AnalyticsPayload) =>
onAnalyticsEvent('PLAYER_LOADED', payload)
);
player.on('VIDEO_STARTED', (payload?: AnalyticsPayload) =>
onAnalyticsEvent('VIDEO_STARTED', payload)
);
player.on('VIDEO_PAUSED', (payload?: AnalyticsPayload) =>
onAnalyticsEvent('VIDEO_PAUSED', payload)
);
player.on('VIDEO_ENDED', (payload?: AnalyticsPayload) =>
onAnalyticsEvent('VIDEO_ENDED', payload)
);
player.on('CUE_TRIGGERED', (payload?: AnalyticsPayload) =>
onAnalyticsEvent('CUE_TRIGGERED', payload)
);
player.on('INTERACTION_COMPLETED', (payload?: AnalyticsPayload) =>
onAnalyticsEvent('INTERACTION_COMPLETED', payload)
);
player.on('ERROR', (payload?: AnalyticsPayload) =>
onAnalyticsEvent('ERROR', payload)
);
}
const playerConfig: PlayerConfig = {
videoUrl,
...restOptions,
};

if (cues) {
player.loadCues(cues);
}
try {
const player = new IVLabsPlayer(uniqueIdRef.current, playerConfig);
playerRef.current = player;

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid re-instantiating the player on every render; stabilize dependencies and callback.

Including restOptions and onAnalyticsEvent in the init effect deps makes the effect run frequently (new object/callback identity), tearing down and recreating the player unnecessarily. This can cause flicker, state loss, and missed cue/translation loads.

Apply these changes:

  • Initialize/destroy the player only when videoUrl changes.
  • Use a ref to hold the latest onAnalyticsEvent to avoid re-binding/recreating.

Diff within this block:

-  useEffect(() => {
-    if (!containerRef.current) return;
-
-    const playerConfig: PlayerConfig = {
-      videoUrl,
-      ...restOptions,
-    };
-
-    try {
-      const player = new IVLabsPlayer(uniqueIdRef.current, playerConfig);
-      playerRef.current = player;
-
-      if (onAnalyticsEvent) {
-        const events: AnalyticsEvent[] = [
-          'PLAYER_LOADED',
-          'VIDEO_STARTED',
-          'VIDEO_PAUSED',
-          'VIDEO_ENDED',
-          'CUE_TRIGGERED',
-          'INTERACTION_COMPLETED',
-          'ERROR',
-        ];
-        events.forEach((event) => {
-          player.on(event, (payload?: AnalyticsPayload) =>
-            onAnalyticsEvent(event, payload)
-          );
-        });
-      }
-    } catch (error) {
-      console.error('Error initializing IVLabsPlayer:', error);
-    }
-
-    return () => {
-      if (playerRef.current) {
-        playerRef.current.destroy();
-        playerRef.current = null;
-      }
-    };
-  }, [videoUrl, onAnalyticsEvent, restOptions]);
+  useEffect(() => {
+    if (!containerRef.current) return;
+    try {
+      // Recreate only when videoUrl changes
+      if (playerRef.current) {
+        playerRef.current.destroy();
+        playerRef.current = null;
+      }
+      const playerConfig: PlayerConfig = { videoUrl, ...restOptions };
+      const player = new IVLabsPlayer(uniqueIdRef.current, playerConfig);
+      playerRef.current = player;
+
+      const events: AnalyticsEvent[] = [
+        'PLAYER_LOADED',
+        'VIDEO_STARTED',
+        'VIDEO_PAUSED',
+        'VIDEO_ENDED',
+        'CUE_TRIGGERED',
+        'INTERACTION_COMPLETED',
+        'ERROR',
+      ];
+      events.forEach((event) => {
+        player.on(event, (payload?: AnalyticsPayload) => {
+          const cb = onAnalyticsRef.current;
+          if (cb) cb(event, payload);
+        });
+      });
+    } catch (error) {
+      console.error('Error initializing IVLabsPlayer:', error);
+    }
+    return () => {
+      if (playerRef.current) {
+        playerRef.current.destroy();
+        playerRef.current = null;
+      }
+    };
+  }, [videoUrl]);

Additions required outside the selected range:

// Keep the latest analytics callback without retriggering init effect
const onAnalyticsRef = useRef<typeof onAnalyticsEvent>(onAnalyticsEvent);
useEffect(() => {
  onAnalyticsRef.current = onAnalyticsEvent;
}, [onAnalyticsEvent]);

Rationale:

  • Prevents unnecessary player churn.
  • Ensures analytics handler updates without re-instantiation.

Also applies to: 73-87, 99-99

🤖 Prompt for AI Agents
In src/index.tsx around lines 62 to 72, the player is being re-instantiated on
every render due to restOptions and onAnalyticsEvent being dependencies in the
effect, causing unnecessary teardown and flicker. To fix this, modify the effect
to only initialize and destroy the player when videoUrl changes. Additionally,
create a ref outside the effect to hold the latest onAnalyticsEvent callback and
update it via a separate useEffect, so the player uses the current callback
without needing to be recreated. Apply similar changes to the effect blocks at
lines 73-87 and line 99.

Comment on lines +101 to +106
useEffect(() => {
if (playerRef.current && cues) {
playerRef.current.loadCues(cues);
}
}, [cues]);

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure cues reload after player re-initialization.

If the player is recreated (e.g., when videoUrl changes), cues won’t reload unless this effect re-runs. Include videoUrl.

-  }, [cues]);
+  }, [cues, videoUrl]);
📝 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
useEffect(() => {
if (playerRef.current && cues) {
playerRef.current.loadCues(cues);
}
}, [cues]);
useEffect(() => {
if (playerRef.current && cues) {
playerRef.current.loadCues(cues);
}
}, [cues, videoUrl]);
🤖 Prompt for AI Agents
In src/index.tsx around lines 101 to 106, the useEffect hook that loads cues
only depends on cues, so if the player is re-initialized due to a change in
videoUrl, the cues won't reload. Add videoUrl to the dependency array of this
useEffect to ensure cues reload whenever the player is recreated or cues change.

Comment on lines +107 to +112
useEffect(() => {
if (playerRef.current && translations) {
const locale = restOptions.locale || 'en';
playerRef.current.loadTranslations(locale, translations);
}
}, [translations, restOptions.locale]);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure translations reload after player re-initialization and locale changes.

Similarly, reload translations when the player is recreated.

-  }, [translations, restOptions.locale]);
+  }, [translations, restOptions.locale, videoUrl]);
🤖 Prompt for AI Agents
In src/index.tsx around lines 107 to 112, the current useEffect reloads
translations only when translations or locale change, but it does not handle
reloading when the player is re-initialized. Modify the effect to also depend on
the player instance or a relevant state that changes when the player is
recreated, so that translations reload whenever the player is re-initialized or
the locale changes.

import pkg from './package.json';

export default defineConfig({
export default defineConfig((options) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

JSON import in config may require TS settings; provide portable fallback.

Importing package.json directly relies on resolveJsonModule (and compatible module resolution). If your env doesn’t guarantee this, prefer createRequire to avoid config-time import issues.

Verification script (checks tsconfig flags):

Optional portable change:

-import pkg from './package.json';
+// Portable JSON access without relying on resolveJsonModule
+import { createRequire } from 'node:module';
+const require = createRequire(import.meta.url);
+const pkg = require('./package.json') as {
+  name: string;
+  version: string;
+  author?: string;
+  license?: string;
+};

Nit: consider enabling sourcemaps for easier debugging:

-  clean: true,
+  clean: true,
+  sourcemap: true,

Also applies to: 7-11, 13-13, 19-22, 23-23


🏁 Script executed:

#!/bin/bash
set -euo pipefail
fd -t f 'tsconfig*.json' | while read -r f; do
  echo "== $f =="
  jq -r '.compilerOptions | {module, moduleResolution, resolveJsonModule, esModuleInterop}' "$f"
done

Length of output: 449


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# For each tsconfig*.json, print key compilerOptions fields
fd -t f 'tsconfig*.json' | while read -r f; do
  echo "== $f =="
  module=$(jq -r '.compilerOptions.module // "undefined"' "$f")
  moduleResolution=$(jq -r '.compilerOptions.moduleResolution // "undefined"' "$f")
  resolveJsonModule=$(jq -r '.compilerOptions.resolveJsonModule // false' "$f")
  esModuleInterop=$(jq -r '.compilerOptions.esModuleInterop // false' "$f")
  echo "module: $module"
  echo "moduleResolution: $moduleResolution"
  echo "resolveJsonModule: $resolveJsonModule"
  echo "esModuleInterop: $esModuleInterop"
done

Length of output: 697


Enable portable JSON import in tsup.config.ts

Your tsconfig.json currently has resolveJsonModule: false, so the direct import pkg from './package.json' will fail under TypeScript compilation. To ensure your config loads package metadata reliably, switch to a Node‐native fallback or enable the compiler flag:

Locations to update:

  • tsup.config.ts (around line 4)
  • tsup.config.ts (config object, around clean: true)

Suggested changes:

--- tsup.config.ts
@@ -1,7 +1,12
-import pkg from './package.json';
+// Portable JSON access without relying on resolveJsonModule
+import { createRequire } from 'node:module';
+const require = createRequire(import.meta.url);
+const pkg = require('./package.json') as {
+  name: string;
+  version: string;
+  author?: string;
+  license?: string;
+};

 export default defineConfig((options) => ({
   clean: true,
+  // Easier debugging of generated bundles
+  sourcemap: true,
   // …
 }));

Alternatively, you can enable JSON imports by setting "resolveJsonModule": true in your tsconfig.json under compilerOptions.

📝 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
export default defineConfig((options) => ({
// Portable JSON access without relying on resolveJsonModule
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const pkg = require('./package.json') as {
name: string;
version: string;
author?: string;
license?: string;
};
export default defineConfig((options) => ({
clean: true,
// Easier debugging of generated bundles
sourcemap: true,
// …
}));
🤖 Prompt for AI Agents
In tsup.config.ts around line 4 and near the config object with clean: true,
avoid directly importing JSON since tsconfig.json has resolveJsonModule set to
false. Instead, replace the JSON import with a Node-native method like using
fs.readFileSync and JSON.parse to load package metadata at runtime.
Alternatively, enable "resolveJsonModule": true in tsconfig.json under
compilerOptions to allow direct JSON imports.

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