Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

[MOC-186] mocksi lite next #146

Merged
merged 16 commits into from
Aug 20, 2024
Merged

[MOC-186] mocksi lite next #146

merged 16 commits into from
Aug 20, 2024

Conversation

fitzk
Copy link
Contributor

@fitzk fitzk commented Aug 15, 2024

Summary by CodeRabbit

  • New Features

    • Introduced automation for managing stale issues in the repository.
    • Implemented a CI workflow for building and packaging the web extension.
    • Defined the configuration for a Chrome extension adhering to Manifest V3 specifications.
    • Enhanced user interaction through new React components for communication via responsive iframes.
    • Created a new popup interface for the extension with a dynamic loading structure.
  • Bug Fixes

    • Improved error handling and logging across various components.
  • Chores

    • Established configuration files for building the web extension project using modern tools and libraries.

Copy link

coderabbitai bot commented Aug 15, 2024

Important

Review skipped

Review was skipped due to path filters

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

This commit enhances a React-based Chrome extension using TypeScript and Vite. It introduces automation for stale issue management, sets up a CI workflow for building the extension, and provides comprehensive manifest files for configuration. New interactive components improve user engagement and functionality, resulting in a richer overall experience.

Changes

File Path Change Summary
.github/stale.yml, .github/workflows/ci.yml Implemented automation for managing stale issues and established a CI workflow for building the extension.
apps/mocksi-lite-next/manifest.json, apps/mocksi-lite-next/manifest.dev.json Created configuration files for the extension using Manifest V3 specifications to enhance functionality.
apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx, apps/mocksi-lite-next/vite.config.ts Introduced React components for dynamic interaction and configured Vite for building the extension.
apps/mocksi-lite-next/nodemon.json Added a Nodemon configuration for monitoring changes during development, enhancing workflow.
apps/mocksi-lite-next/src/pages/content/index.css, apps/mocksi-lite-next/tailwind.config.cjs Integrated Tailwind CSS and added styles to create a clean and responsive layout for the application.
apps/mocksi-lite-next/tsconfig.json Enhanced TypeScript configuration to optimize module resolution and streamline the build process.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Popup
    participant Content
    participant Background

    User->>Popup: Opens extension popup
    Popup->>User: Displays interface

    User->>Content: Sends message to content script
    Content->>Background: Processes message
    Background->>Content: Sends back response
    Content->>User: Updates content based on response

    User->>Popup: Closes popup
Loading

🐰 In the meadow, changes bloom,
A new extension dispels the gloom.
With React and Vite, oh what a sight,
Tailwind wraps it snug and tight.
Let’s hop along, our code is grand,
Together we’ll build, just as we planned! 🥕✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@fitzk fitzk changed the title Moc 186 mocksi lite next [MOC-186] mocksi lite next Aug 15, 2024
Copy link

linear bot commented Aug 15, 2024

Copy link

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

Outside diff range, codebase verification and nitpick comments (12)
apps/mocksi-lite-next/.github/workflows/ci.yml (2)

1-3: Consider adding more triggers.

Currently, the workflow is triggered only by workflow_dispatch. Consider adding other triggers like push or pull_request to automate builds on code changes.

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
  workflow_dispatch:

15-15: Consider increasing fetch-depth.

The fetch-depth is set to 2. If your build process requires more history (e.g., for versioning), consider increasing this value.

apps/mocksi-lite-next/package.json (2)

7-7: Clarify the project description.

The description could be more specific about the project's purpose or target audience to enhance clarity.

- "description": "A simple chrome extension template with Vite, React, TypeScript and Tailwind CSS.",
+ "description": "A boilerplate for creating Chrome extensions using Vite, React, TypeScript, and Tailwind CSS."

40-44: Review the dev script configuration in package.json.

The nodemon configuration in nodemon.json is set to execute vite build, which is more typical for a build process rather than running a development server. This setup is unconventional for a Vite-based React project, where the dev script usually starts a development server. Consider revising the dev script to align with standard Vite development practices.

  • File: apps/mocksi-lite-next/package.json
  • Configuration File: apps/mocksi-lite-next/nodemon.json
Analysis chain

Ensure script commands are correct and sufficient.

The dev script uses nodemon, which is typically used for Node.js applications. Verify if this is the intended behavior for a Vite-based React project.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of nodemon in the dev script.

# Test: Check if nodemon is correctly configured for a Vite-based React project.
grep -r "nodemon" . --include "*.js" --include "*.ts"

Length of output: 53


Script:

#!/bin/bash
# Description: Search for nodemon configuration in package.json and any nodemon configuration files.

# Check for nodemon configuration in package.json
grep -A 5 '"nodemon"' package.json

# Look for nodemon configuration files
fd -e json -e js -e ts -e yaml -e yml -g 'nodemon*'

Length of output: 125


Script:

#!/bin/bash
# Description: Output the contents of nodemon.json to review its configuration.

cat apps/mocksi-lite-next/nodemon.json

Length of output: 273

apps/mocksi-lite-next/vite.config.ts (2)

3-3: Remove unused import fs.

The fs module is imported but not used in the code. Consider removing it to clean up the imports.

- import fs from 'fs';

27-41: Fix typo in console log messages.

The word "frm" should be corrected to "from" in the console log messages.

- fs.rm(resolve(outDir, 'dev-icon-32.png'), () => console.log(`Deleted dev-icon-32.png frm prod build`))
- fs.rm(resolve(outDir, 'dev-icon-128.png'), () => console.log(`Deleted dev-icon-128.png frm prod build`))
+ fs.rm(resolve(outDir, 'dev-icon-32.png'), () => console.log(`Deleted dev-icon-32.png from prod build`))
+ fs.rm(resolve(outDir, 'dev-icon-128.png'), () => console.log(`Deleted dev-icon-128.png from prod build`))
apps/mocksi-lite-next/README.md (6)

33-33: Add a comma for clarity.

Consider adding a comma after "building" for improved readability.

> For improved DX and rapid building, vite and nodemon are used.
Tools
LanguageTool

[uncategorized] ~33-~33: Possible missing comma found.
Context: ... Built for: > For improved DX and rapid building vite and nodemon are used. > Chrome do...

(AI_HYDRA_LEO_MISSING_COMMA)


44-44: Punctuate interjections for clarity.

Add punctuation to the interjection for better readability.

- Oh by the way ...
+ Oh, by the way, ...

48-48: Consider using a synonym for "hard to".

To elevate the writing, consider using a synonym for "hard to".

- found it too hard to configure.
+ found it too challenging to configure.
Tools
LanguageTool

[style] ~48-~48: To elevate your writing, try using a synonym here.
Context: ...ack react boilerplates and found it too hard to configure. Vite is mega easy to und...

(HARD_TO)


50-50: Add a comma for clarity.

Consider adding a comma after "understand" for improved readability.

- Vite is mega easy to understand which makes it easier to get into and to maintain for others.
+ Vite is mega easy to understand, which makes it easier to get into and to maintain for others.
Tools
LanguageTool

[uncategorized] ~50-~50: Possible missing comma found.
Context: ...ard to configure. Vite is mega easy to understand which makes it easier to get into and t...

(AI_HYDRA_LEO_MISSING_COMMA)


109-109: Remove duplicated word "Vite".

The word "Vite" is repeated. Consider removing the duplication.

- - [Vite](https://vitejs.dev/)
Tools
LanguageTool

[duplication] ~109-~109: Possible typo: you repeated a word
Context: ...h/) # Tech Docs - Vite - [Vite Plugin](https://vitejs.dev/guide/api-pl...

(ENGLISH_WORD_REPEAT_RULE)


117-117: Capitalize "Chrome" for consistency.

The proper noun "Chrome" should be capitalized.

- vite chrome extension boilerplate
+ Vite Chrome extension boilerplate
Tools
LanguageTool

[grammar] ~117-~117: The proper noun “Chrome” (= software from Google) needs to be capitalized.
Context: ... Heavily inspired by [Jonghakseo's vite chrome extension boilerplate](https://github.c...

(GOOGLE_PRODUCTS)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b9be522 and d405283.

Files ignored due to path filters (6)
  • apps/mocksi-lite-next/public/dev-icon-128.png is excluded by !**/*.png
  • apps/mocksi-lite-next/public/dev-icon-32.png is excluded by !**/*.png
  • apps/mocksi-lite-next/public/icon-128.png is excluded by !**/*.png
  • apps/mocksi-lite-next/public/icon-32.png is excluded by !**/*.png
  • apps/mocksi-lite-next/src/assets/img/logo.svg is excluded by !**/*.svg
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (40)
  • apps/mocksi-lite-next/.eslintrc (1 hunks)
  • apps/mocksi-lite-next/.github/stale.yml (1 hunks)
  • apps/mocksi-lite-next/.github/workflows/ci.yml (1 hunks)
  • apps/mocksi-lite-next/.gitignore (1 hunks)
  • apps/mocksi-lite-next/.nvmrc (1 hunks)
  • apps/mocksi-lite-next/LICENSE (1 hunks)
  • apps/mocksi-lite-next/README.md (1 hunks)
  • apps/mocksi-lite-next/manifest.dev.json (1 hunks)
  • apps/mocksi-lite-next/manifest.json (1 hunks)
  • apps/mocksi-lite-next/nodemon.json (1 hunks)
  • apps/mocksi-lite-next/package.json (1 hunks)
  • apps/mocksi-lite-next/postcss.config.cjs (1 hunks)
  • apps/mocksi-lite-next/src/assets/styles/tailwind.css (1 hunks)
  • apps/mocksi-lite-next/src/global.d.ts (1 hunks)
  • apps/mocksi-lite-next/src/pages/background/index.ts (1 hunks)
  • apps/mocksi-lite-next/src/pages/content/index.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/content/style.css (1 hunks)
  • apps/mocksi-lite-next/src/pages/devtools/index.html (1 hunks)
  • apps/mocksi-lite-next/src/pages/devtools/index.ts (1 hunks)
  • apps/mocksi-lite-next/src/pages/newtab/Newtab.css (1 hunks)
  • apps/mocksi-lite-next/src/pages/newtab/Newtab.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/newtab/index.css (1 hunks)
  • apps/mocksi-lite-next/src/pages/newtab/index.html (1 hunks)
  • apps/mocksi-lite-next/src/pages/newtab/index.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/options/Options.css (1 hunks)
  • apps/mocksi-lite-next/src/pages/options/Options.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/options/index.html (1 hunks)
  • apps/mocksi-lite-next/src/pages/options/index.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/panel/Panel.css (1 hunks)
  • apps/mocksi-lite-next/src/pages/panel/Panel.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/panel/index.html (1 hunks)
  • apps/mocksi-lite-next/src/pages/panel/index.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/popup/Popup.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/popup/index.css (1 hunks)
  • apps/mocksi-lite-next/src/pages/popup/index.html (1 hunks)
  • apps/mocksi-lite-next/src/pages/popup/index.tsx (1 hunks)
  • apps/mocksi-lite-next/src/vite-env.d.ts (1 hunks)
  • apps/mocksi-lite-next/tailwind.config.cjs (1 hunks)
  • apps/mocksi-lite-next/tsconfig.json (1 hunks)
  • apps/mocksi-lite-next/vite.config.ts (1 hunks)
Files skipped from review due to trivial changes (25)
  • apps/mocksi-lite-next/.github/stale.yml
  • apps/mocksi-lite-next/.gitignore
  • apps/mocksi-lite-next/.nvmrc
  • apps/mocksi-lite-next/LICENSE
  • apps/mocksi-lite-next/manifest.dev.json
  • apps/mocksi-lite-next/postcss.config.cjs
  • apps/mocksi-lite-next/src/assets/styles/tailwind.css
  • apps/mocksi-lite-next/src/global.d.ts
  • apps/mocksi-lite-next/src/pages/background/index.ts
  • apps/mocksi-lite-next/src/pages/content/style.css
  • apps/mocksi-lite-next/src/pages/devtools/index.html
  • apps/mocksi-lite-next/src/pages/newtab/Newtab.css
  • apps/mocksi-lite-next/src/pages/newtab/Newtab.tsx
  • apps/mocksi-lite-next/src/pages/newtab/index.css
  • apps/mocksi-lite-next/src/pages/newtab/index.html
  • apps/mocksi-lite-next/src/pages/options/Options.css
  • apps/mocksi-lite-next/src/pages/options/Options.tsx
  • apps/mocksi-lite-next/src/pages/options/index.html
  • apps/mocksi-lite-next/src/pages/panel/Panel.css
  • apps/mocksi-lite-next/src/pages/panel/Panel.tsx
  • apps/mocksi-lite-next/src/pages/popup/index.css
  • apps/mocksi-lite-next/src/pages/popup/index.html
  • apps/mocksi-lite-next/src/vite-env.d.ts
  • apps/mocksi-lite-next/tailwind.config.cjs
  • apps/mocksi-lite-next/tsconfig.json
Additional context used
LanguageTool
apps/mocksi-lite-next/README.md

[uncategorized] ~33-~33: Possible missing comma found.
Context: ... Built for: > For improved DX and rapid building vite and nodemon are used. > Chrome do...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~43-~43: Interjections are usually punctuated.
Context: ...rt will be added in this repo as well. Oh by the way ... I also implemented a chr...

(INTERJECTIONS_PUNCTUATION)


[style] ~48-~48: To elevate your writing, try using a synonym here.
Context: ...ack react boilerplates and found it too hard to configure. Vite is mega easy to und...

(HARD_TO)


[uncategorized] ~50-~50: Possible missing comma found.
Context: ...ard to configure. Vite is mega easy to understand which makes it easier to get into and t...

(AI_HYDRA_LEO_MISSING_COMMA)


[duplication] ~109-~109: Possible typo: you repeated a word
Context: ...h/) # Tech Docs - Vite - [Vite Plugin](https://vitejs.dev/guide/api-pl...

(ENGLISH_WORD_REPEAT_RULE)


[grammar] ~117-~117: The proper noun “Chrome” (= software from Google) needs to be capitalized.
Context: ... Heavily inspired by [Jonghakseo's vite chrome extension boilerplate](https://github.c...

(GOOGLE_PRODUCTS)

Markdownlint
apps/mocksi-lite-next/README.md

39-39: Expected: dash; Actual: asterisk
Unordered list style

(MD004, ul-style)


40-40: Expected: dash; Actual: asterisk
Unordered list style

(MD004, ul-style)


34-34: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)


36-36: null
Blank line inside blockquote

(MD028, no-blanks-blockquote)

Additional comments not posted (16)
apps/mocksi-lite-next/nodemon.json (1)

12-12: Question the use of vite build in development configuration.

The exec command is set to vite build, which is typically used for production builds. For development, consider using vite dev to enable hot module replacement and faster feedback loops.

apps/mocksi-lite-next/src/pages/panel/index.html (1)

1-11: HTML structure is well-formed and appropriate.

The HTML file provides a minimal setup for a React application, using a root div and a module script. This is a good practice for initializing a single-page application.

apps/mocksi-lite-next/src/pages/options/index.tsx (1)

1-13: LGTM!

The code correctly sets up the React component for the options page. The use of createRoot and error handling for the root element is appropriate.

apps/mocksi-lite-next/src/pages/panel/index.tsx (1)

1-14: LGTM!

The setup for the panel page is consistent and well-structured. The inclusion of Tailwind CSS is a good choice for styling. Error handling for the root element is correctly implemented.

apps/mocksi-lite-next/src/pages/popup/index.tsx (1)

1-14: LGTM!

The code for the popup page is consistent with the other parts of the extension. The use of Tailwind CSS for styling and error handling for the root element is appropriate.

apps/mocksi-lite-next/src/pages/newtab/index.tsx (1)

1-14: LGTM!

The setup for initializing the Newtab component is clear and follows best practices for React applications. The error handling for the root element is appropriate.

apps/mocksi-lite-next/src/pages/content/index.tsx (1)

1-20: LGTM!

The content script is well-structured, correctly creating and appending a root element to the document body. The error handling and console log statements are appropriate for debugging.

apps/mocksi-lite-next/.eslintrc (1)

1-34: LGTM!

The ESLint configuration is well-structured and comprehensive, covering necessary environments and plugins for a TypeScript and React project. The ignore patterns and global variables are appropriately set.

apps/mocksi-lite-next/.github/workflows/ci.yml (3)

9-9: Increase timeout if necessary.

The timeout is set to 15 minutes. Ensure this is sufficient for your build process, especially if additional steps are added later.


21-21: Verify the use of pnpm cache.

Ensure that using pnpm cache is beneficial for your workflow. If not configured correctly, it might not provide the expected performance improvements.


29-33: Ensure correct artifact path.

Verify that the dist path contains all necessary files for the extension. If the build output changes, update this path accordingly.

apps/mocksi-lite-next/src/pages/popup/Popup.tsx (2)

1-1: Ensure consistent import paths.

The import path for the logo uses an alias (@assets). Ensure that this alias is correctly configured in your build setup.


18-20: Ensure external links open safely.

The link to React's website uses noopener noreferrer, which is good for security. Ensure all external links follow this practice.

apps/mocksi-lite-next/manifest.json (2)

24-26: Review permissions for necessity.

The activeTab permission is included. Review and ensure that only necessary permissions are requested to minimize security risks.


29-32: Avoid using <all_urls> unless necessary.

The content script matches <all_urls>, which can be a security risk. Ensure this is necessary and consider narrowing the scope if possible.

apps/mocksi-lite-next/package.json (1)

3-5: Verify React version compatibility.

Ensure that React version 18.3.1 is compatible with all other dependencies, especially react-dom.

Comment on lines +3 to +5
Browser.devtools.panels
.create("Dev Tools", "icon-32.png", "src/pages/panel/index.html")
.catch(console.error);
Copy link

Choose a reason for hiding this comment

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

Improve error handling for better debugging.

While the current error handling logs errors to the console, it would be beneficial to add more context to the error message to aid in debugging.

-  .catch(console.error);
+  .catch((error) => console.error("Failed to create DevTools panel:", error));
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
Browser.devtools.panels
.create("Dev Tools", "icon-32.png", "src/pages/panel/index.html")
.catch(console.error);
Browser.devtools.panels
.create("Dev Tools", "icon-32.png", "src/pages/panel/index.html")
.catch((error) => console.error("Failed to create DevTools panel:", error));

Comment on lines 9 to 11
src={logo}
className="h-36 pointer-events-none animate-spin-slow"
alt="logo"
Copy link

Choose a reason for hiding this comment

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

Optimize image loading.

Consider optimizing the logo image for performance, especially if it is large. You might use a smaller version or lazy loading if applicable.

Comment on lines 45 to 51
"resources": [
"contentStyle.css",
"icon-128.png",
"icon-32.png"
],
"matches": []
}
Copy link

Choose a reason for hiding this comment

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

Consider specifying matches for web accessible resources.

Currently, the matches array for web_accessible_resources is empty. Specify the URLs that should have access to these resources to enhance security.

Comment on lines 35 to 39
renderStart (outputOptions: any, inputOptions: any) {
const outDir = outputOptions.dir
fs.rm(resolve(outDir, 'dev-icon-32.png'), () => console.log(`Deleted dev-icon-32.png frm prod build`))
fs.rm(resolve(outDir, 'dev-icon-128.png'), () => console.log(`Deleted dev-icon-128.png frm prod build`))
}
Copy link

Choose a reason for hiding this comment

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

Ensure error handling for file removal.

Consider adding error handling for the fs.rm operations to handle potential errors during file removal.

- fs.rm(resolve(outDir, 'dev-icon-32.png'), () => console.log(`Deleted dev-icon-32.png from prod build`))
- fs.rm(resolve(outDir, 'dev-icon-128.png'), () => console.log(`Deleted dev-icon-128.png from prod build`))
+ fs.rm(resolve(outDir, 'dev-icon-32.png'), (err) => {
+   if (err) console.error(`Error deleting dev-icon-32.png:`, err);
+   else console.log(`Deleted dev-icon-32.png from prod build`);
+ })
+ fs.rm(resolve(outDir, 'dev-icon-128.png'), (err) => {
+   if (err) console.error(`Error deleting dev-icon-128.png:`, err);
+   else console.log(`Deleted dev-icon-128.png from prod build`);
+ })
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
renderStart (outputOptions: any, inputOptions: any) {
const outDir = outputOptions.dir
fs.rm(resolve(outDir, 'dev-icon-32.png'), () => console.log(`Deleted dev-icon-32.png frm prod build`))
fs.rm(resolve(outDir, 'dev-icon-128.png'), () => console.log(`Deleted dev-icon-128.png frm prod build`))
}
renderStart (outputOptions: any, inputOptions: any) {
const outDir = outputOptions.dir
fs.rm(resolve(outDir, 'dev-icon-32.png'), (err) => {
if (err) console.error(`Error deleting dev-icon-32.png:`, err);
else console.log(`Deleted dev-icon-32.png from prod build`);
})
fs.rm(resolve(outDir, 'dev-icon-128.png'), (err) => {
if (err) console.error(`Error deleting dev-icon-128.png:`, err);
else console.log(`Deleted dev-icon-128.png from prod build`);
})
}

Copy link
Contributor

@elg0nz elg0nz left a comment

Choose a reason for hiding this comment

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

Just a couple early comments. The manifest changes look important but everything else can wait

@@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I wasn't aware this config existed

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove this file. We already have a LICENSE file on the root of this repo.

@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 Jonathan Braat
Copy link
Contributor

Choose a reason for hiding this comment

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

Plus we're not Jonathan 😜

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha for sure removed, just boilerplate

@@ -0,0 +1,121 @@
<div align="center">
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to @elg0nz : update this readme after merging this PR

"128": "icon-128.png"
},
"permissions": [
"activeTab"
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll probably need the whole list from here:

"permissions": [
"activeTab",
"background",
"cookies",
"downloads",
"debugger",
"scripting",
"storage",
"tabs",
"webNavigation",
"webRequest"

Kayla Fitzsimmons added 2 commits August 16, 2024 11:38
Copy link

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

Outside diff range, codebase verification and nitpick comments (4)
.github/workflows/ci.yml (2)

9-9: Consider reducing the timeout if possible.

The timeout for the build job is set to 15 minutes. If the build process typically completes much faster, consider reducing this timeout to prevent unnecessary delays in case of hanging jobs.


21-21: Consider using a lockfile for caching.

Using a lockfile for caching can improve build consistency and performance. Ensure that your project uses a lockfile compatible with pnpm.

apps/mocksi-lite-next/src/pages/content/AppIFrame.tsx (2)

15-16: Remove or adjust console.log statements in production.

The console.log statement is useful for debugging but should be removed or adjusted for production to avoid cluttering the console.

- console.log("doc on load!", document);
+ // console.log("doc on load!", document); // Uncomment for debugging

21-28: Ensure sanitization of event target to prevent exposure of sensitive information.

The event.target is being used directly in messages sent via chrome.runtime.sendMessage without any sanitization or validation. It's important to ensure that sensitive information is not inadvertently exposed. Consider implementing a mechanism to sanitize or validate the event.target before using it in messages.

  • File: apps/mocksi-lite-next/src/pages/content/AppIFrame.tsx
  • Lines: 21-28
Analysis chain

Ensure proper handling of event target.

The event target is being logged and sent in messages. Ensure that sensitive information is not inadvertently exposed, and consider sanitizing the event target if necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify handling of event target to ensure no sensitive information is exposed.

# Test: Check for any sanitization or validation of event targets in the codebase.
rg --type js 'event.target' -A 5

Length of output: 32


Script:

#!/bin/bash
# Description: Check for any sanitization or validation of event targets in the specific file.

# Search for usage of event.target in the AppIFrame.tsx file and check surrounding lines for sanitization or validation.
rg 'event.target' -A 5 -B 5 apps/mocksi-lite-next/src/pages/content/AppIFrame.tsx

Length of output: 393

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d405283 and 32b971a.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (7)
  • .github/stale.yml (1 hunks)
  • .github/workflows/ci.yml (1 hunks)
  • apps/mocksi-lite-next/manifest.json (1 hunks)
  • apps/mocksi-lite-next/package.json (1 hunks)
  • apps/mocksi-lite-next/src/pages/background/index.ts (1 hunks)
  • apps/mocksi-lite-next/src/pages/content/AppIFrame.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/content/index.tsx (1 hunks)
Files skipped from review due to trivial changes (2)
  • .github/stale.yml
  • apps/mocksi-lite-next/package.json
Files skipped from review as they are similar to previous changes (3)
  • apps/mocksi-lite-next/manifest.json
  • apps/mocksi-lite-next/src/pages/background/index.ts
  • apps/mocksi-lite-next/src/pages/content/index.tsx
Additional comments not posted (3)
.github/workflows/ci.yml (3)

32-33: Verify artifact path correctness.

The artifact path is set to dist. Ensure that this path is correct and contains the desired build outputs.


20-20: Ensure Node.js version compatibility.

The Node.js version is set to 18. Ensure that your project and all dependencies are compatible with this version.

Verification successful

Node.js version 18 is compatible with the project.

The project's package.json specifies compatibility with Node.js version 18 and above. No additional constraints were found in internal packages. Ensure that any hidden dependencies also adhere to this requirement.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify compatibility of Node.js version 18 with project dependencies.

# Test: Check package.json for any version constraints or scripts that might indicate compatibility issues.
rg --type json '"node":' package.json -A 5

Length of output: 194


Script:

#!/bin/bash
# Description: Check the Node.js version constraints in the package.json files of internal packages.

# Find all package.json files in the repository and search for Node.js version constraints.
fd package.json | xargs rg --type json '"node":' -A 5

Length of output: 283


15-15: Verify if fetch-depth is sufficient.

The fetch-depth is set to 2. Ensure this depth is sufficient for your build process, especially if you rely on commit history for versioning or other purposes.

Comment on lines 5 to 12
document.body.addEventListener("click", (event) => {
chrome.runtime.sendMessage(
`${event.target} clicked in main document`,
(response) => {
console.log("response from background script", response);
},
);
});
Copy link

Choose a reason for hiding this comment

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

Avoid adding event listeners directly to document.body.

Adding event listeners directly to document.body can lead to potential memory leaks and unintended behavior. Consider using the useEffect hook to manage the lifecycle of the event listener.

useEffect(() => {
  const handleClick = (event) => {
    chrome.runtime.sendMessage(
      `${event.target} clicked in main document`,
      (response) => {
        console.log("response from background script", response);
      }
    );
  };

  document.body.addEventListener("click", handleClick);

  return () => {
    document.body.removeEventListener("click", handleClick);
  };
}, []);

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 32b971a and 17c127a.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (5)
  • apps/mocksi-lite-next/manifest.json (1 hunks)
  • apps/mocksi-lite-next/package.json (1 hunks)
  • apps/mocksi-lite-next/src/pages/background/index.ts (1 hunks)
  • apps/mocksi-lite-next/src/pages/content/ExtensionIframe.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/content/index.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/mocksi-lite-next/package.json
Files skipped from review as they are similar to previous changes (3)
  • apps/mocksi-lite-next/manifest.json
  • apps/mocksi-lite-next/src/pages/background/index.ts
  • apps/mocksi-lite-next/src/pages/content/index.tsx
Additional comments not posted (1)
apps/mocksi-lite-next/src/pages/content/ExtensionIframe.tsx (1)

17-17: LGTM!

The export statement correctly exports the ExtensionIframe component as default.

Comment on lines 3 to 15
function ExtensionIframe() {
const iframeRef = useRef();
return (
<iframe
ref={iframeRef.current}
src="http://localhost:3030/extension"
style={{
height: "800px",
width: "500px",
}}
/>
);
}
Copy link

@coderabbitai coderabbitai bot Aug 17, 2024

Choose a reason for hiding this comment

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

Ensure the iframe src URL is configurable.

The iframe src is hardcoded to http://localhost:3030/extension. This should be configurable to allow for different environments (e.g., development, production).

const iframeSrc = process.env.REACT_APP_IFRAME_SRC || "http://localhost:3030/extension";

And update the src attribute:

-  src="http://localhost:3030/extension"
+  src={iframeSrc}

Copy link
Contributor

Choose a reason for hiding this comment

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

The iframesrc will be http://nest-auth-ts-merge.onrender.com/app or something like that.
(and yes, I don't love that this is called nest-auth but we can change that later)

Copy link

Choose a reason for hiding this comment

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

@elg0nz, thank you for specifying the new URL for the iframe source. To accommodate potential future changes, it would be beneficial to make the iframe source URL configurable. This way, you can easily update it without modifying the codebase each time. Let me know if you need any assistance with implementing this change!

const iframeRef = useRef();
return (
<iframe
ref={iframeRef.current}
Copy link

Choose a reason for hiding this comment

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

Correct the ref assignment in the iframe.

The ref attribute should be assigned directly to iframeRef, not iframeRef.current.

-  ref={iframeRef.current}
+  ref={iframeRef}
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
ref={iframeRef.current}
ref={iframeRef}

@@ -0,0 +1,17 @@
import { useRef } from "react";
Copy link

Choose a reason for hiding this comment

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

Specify the type for useRef.

The useRef hook is used without specifying a type. This can lead to type safety issues in TypeScript.

-  const iframeRef = useRef();
+  const iframeRef = useRef<HTMLIFrameElement>(null);
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
import { useRef } from "react";
import { useRef } from "react";
const iframeRef = useRef<HTMLIFrameElement>(null);

Copy link
Contributor

@elg0nz elg0nz left a comment

Choose a reason for hiding this comment

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

One word (emoji): 🔥

"default_icon": {
"32": "icon-32.png"
},
"default_popup": "src/pages/popup/index.html"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we might not need the popup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed it from prod manifest but kept it in dev manifest so we can play around with it easily if we want to use it

"type": "module"
},
"chrome_url_overrides": {
"newtab": "src/pages/newtab/index.html"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should chat with Stephan what we want to do with new tab, I think this could be a great way to ask our users to pin the extension to the bar.

}
],
"content_security_policy": {
"extension_pages": "object-src 'none'; child-src http://localhost:3030; frame-src http://localhost:3030; script-src 'self'"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add http://nest-auth-ts-merge.onrender.com to the list 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added to manifest.json and moved this config to manifest.dev.json

"description": "<description in manifest.json>",
"devtools_page": "src/pages/devtools/index.html",
"externally_connectable": {
"matches": ["http://localhost:3030/*"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 3 to 15
function ExtensionIframe() {
const iframeRef = useRef();
return (
<iframe
ref={iframeRef.current}
src="http://localhost:3030/extension"
style={{
height: "800px",
width: "500px",
}}
/>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The iframesrc will be http://nest-auth-ts-merge.onrender.com/app or something like that.
(and yes, I don't love that this is called nest-auth but we can change that later)

Copy link

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

Outside diff range, codebase verification and nitpick comments (5)
apps/mocksi-lite-next/src/pages/background/index.ts (1)

1-1: Consider removing or refining console logs for production.

The console.log statement is useful for debugging but should be removed or replaced with a more robust logging solution in production.

- console.log("background script loaded");
+ // console.log("background script loaded");
apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (4)

7-8: Avoid using @ts-ignore without explanation.

Using @ts-ignore suppresses TypeScript errors, which can lead to unexpected issues. Consider providing a comment explaining why it's necessary.

// @ts-ignore: Explanation of why this is necessary

11-11: Improve error handling when querying the root container.

Throwing a generic error might not provide enough context. Consider adding more details to the error message.

- if (!rootContainer) throw new Error("Can't find Content root element");
+ if (!rootContainer) throw new Error("Can't find content root element with id '__root'");

35-37: Consider removing or refining console logs for production.

The console.log statement is useful for debugging but should be removed or replaced with a more robust logging solution in production.

- console.log("is small: ", small);
+ // console.log("is small: ", small);

81-85: Consider refining error handling in the try-catch block.

The catch block could provide more context or handle specific error types.

catch (e) {
  console.error("Error loading content script:", e);
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 17c127a and 1b4a6aa.

Files selected for processing (6)
  • apps/mocksi-lite-next/manifest.json (1 hunks)
  • apps/mocksi-lite-next/src/pages/background/index.ts (1 hunks)
  • apps/mocksi-lite-next/src/pages/content/index.css (1 hunks)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (1 hunks)
  • apps/mocksi-lite-next/src/pages/popup/index.html (1 hunks)
  • apps/mocksi-lite-next/src/pages/popup/index.tsx (1 hunks)
Files skipped from review due to trivial changes (3)
  • apps/mocksi-lite-next/src/pages/content/index.css
  • apps/mocksi-lite-next/src/pages/popup/index.html
  • apps/mocksi-lite-next/src/pages/popup/index.tsx
Files skipped from review as they are similar to previous changes (1)
  • apps/mocksi-lite-next/manifest.json

Comment on lines +3 to +10
chrome.runtime.onMessage.addListener(
(request, _sender, sendResponse): boolean => {
console.log("Received message:", request);

sendResponse({ message: request.message, status: "ok" });
return true;
},
);
Copy link

Choose a reason for hiding this comment

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

Ensure proper error handling in message listeners.

The message listener should include error handling to manage unexpected scenarios gracefully.

chrome.runtime.onMessage.addListener(
  (request, _sender, sendResponse): boolean => {
    try {
      console.log("Received message:", request);
      sendResponse({ message: request.message, status: "ok" });
    } catch (error) {
      console.error("Error processing message:", error);
      sendResponse({ status: "error", error: error.message });
    }
    return true;
  },
);

Comment on lines 21 to 33
React.useEffect(() => {
// @ts-expect-error
chrome.runtime.onMessage.addListener(
(request, _sender, sendResponse): boolean => {
console.log("Received message in content script:", request);

setSmall((p) => !p);

sendResponse({ message: request.message, status: "ok" });
return true;
},
);
}, []);
Copy link

Choose a reason for hiding this comment

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

Ensure cleanup for message listeners in useEffect.

The useEffect hook should return a cleanup function to remove the message listener when the component unmounts.

React.useEffect(() => {
  const listener = (request, _sender, sendResponse): boolean => {
    console.log("Received message in content script:", request);
    setSmall((p) => !p);
    sendResponse({ message: request.message, status: "ok" });
    return true;
  };

  // @ts-expect-error
  chrome.runtime.onMessage.addListener(listener);

  return () => {
    // @ts-expect-error
    chrome.runtime.onMessage.removeListener(listener);
  };
}, []);

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b4a6aa and 3bfe74a.

Files selected for processing (2)
  • apps/mocksi-lite-next/src/pages/background/index.ts (1 hunks)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • apps/mocksi-lite-next/src/pages/background/index.ts
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3bfe74a and 9b1518e.

Files selected for processing (1)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9b1518e and 0e316fb.

Files selected for processing (4)
  • apps/mocksi-lite-next/manifest.dev.json (1 hunks)
  • apps/mocksi-lite-next/manifest.json (1 hunks)
  • apps/mocksi-lite-next/nodemon.json (1 hunks)
  • apps/mocksi-lite-next/vite.config.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • apps/mocksi-lite-next/manifest.json
  • apps/mocksi-lite-next/nodemon.json
  • apps/mocksi-lite-next/vite.config.ts
Additional comments not posted (7)
apps/mocksi-lite-next/manifest.dev.json (7)

2-6: Verify the icon path.

The "action" section configuration looks good. Ensure that the icon-32.png file exists at the specified path.


8-10: Verify the new tab page path.

The "chrome_url_overrides" section configuration looks good. Ensure that src/pages/newtab/index.html exists and is correctly implemented.


11-13: Caution: Content Security Policy for development.

The "content_security_policy" allows child-src and frame-src from http://localhost:3030. This is acceptable for development but ensure these are updated for production to enhance security.


14-14: Verify the devtools page path.

The "devtools_page" configuration looks good. Ensure that src/pages/devtools/index.html exists and is correctly implemented.


15-17: Caution: Externally connectable for development.

The "externally_connectable" setting allows connections from http://localhost:3030. This is fine for development but ensure it is restricted in production.


18-18: Approved: Extension name for development.

The "name" is appropriately set for the development version of the extension.


19-21: Verify the options page path.

The "options_ui" configuration looks good. Ensure that src/pages/options/index.html exists and is correctly implemented.

@fitzk fitzk marked this pull request as ready for review August 20, 2024 14:53
Copy link
Contributor

@elg0nz elg0nz left a comment

Choose a reason for hiding this comment

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

👽 🛸


setIframeSize(request.message);

if (iframeRef.current) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

if (iframeRef.current) {
  const styleMap: { [key: string]: Partial<CSSStyleDeclaration> } = {
    "xs-bottom": {
      height: "100px",
      width: "100px",
      bottom: "10px",
      top: "auto",
    },
    "sm-top": {
      height: "150px",
      width: "400px",
      top: "0px",
      bottom: "auto",
    },
    "lg-bottom": {
      height: "600px",
      width: "500px",
      bottom: "10px",
      top: "auto",
    },
  };

  const styles = styleMap[request.message];
  if (styles) {
    Object.assign(iframeRef.current.style, styles);
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is nicer

<html>
<head>
<meta charset="UTF-8" />
<title>Mocksi Lite Next</title>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think this title is ever shown but still it should be Mocksi Lite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ha good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe I will just delete these but after I merge

@@ -0,0 +1,13 @@
// import { createRoot } from "react-dom/client";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would just remove this file :)

@fitzk fitzk merged commit 3050293 into main Aug 20, 2024
3 checks passed
@fitzk fitzk deleted the MOC-186_mocksi-lite-next branch August 20, 2024 16:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants