Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix externalize bug #4984

Merged
merged 2 commits into from
Oct 24, 2024
Merged

fix externalize bug #4984

merged 2 commits into from
Oct 24, 2024

Conversation

sashankaryal
Copy link
Contributor

@sashankaryal sashankaryal commented Oct 24, 2024

#4970 introduced changes that externalized more FO packages to be used in JS plugins. However, some of the packages externalized is causing the app to not build (specifically, @fiftyone/plugin module is not being resolved properly). The reason is unknown and will be investigated later.

This PR removes the culprit packages. This is a fine trade-off for now since these packages aren't expected to be used in JS plugins.

Summary by CodeRabbit

  • New Features

    • Streamlined import process for the Looker3d module, enhancing accessibility for users.
    • Updated global declarations to reflect new dependencies, improving module organization.
  • Bug Fixes

    • Removed outdated imports and properties, ensuring a cleaner and more efficient codebase.

Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • app/packages/looker-3d/package.json is excluded by !**/*.json
  • app/yarn.lock is excluded by !**/yarn.lock, !**/*.lock, !**/*.lock

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

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

Walkthrough

This pull request introduces changes to two files within the project. In the looker-3d package, the index.ts file is updated to re-export all entities from the Looker3d module, enhancing accessibility. In the plugins package, the externalize.ts file undergoes a restructuring of import statements, removing several from the @fiftyone namespace and adding new imports. Corresponding updates are made to the global Window interface, reflecting these changes by adding and removing specific properties.

Changes

File Path Change Summary
app/packages/looker-3d/src/index.ts Added export statement to re-export all entities from the Looker3d module.
app/packages/plugins/src/externalize.ts Modified import statements, removing several @fiftyone imports and adding new ones; updated global Window interface accordingly.

Possibly related PRs

  • externalize @fiftyone/plugins #4897: The changes in this PR involve modifications to the externalize.ts file, specifically adding a new import statement for the @fiftyone/plugins module, which is relevant to the changes made in the main PR that also involves the externalize.ts file and its exports.

Suggested labels

bug

Suggested reviewers

  • ritch

🐇 In the land of code so bright,
Exports dance in morning light.
With imports changed, the structure's new,
A streamlined path for me and you.
Hops of joy, we celebrate,
In the world of code, we innovate! 🎉


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>, please review it.
    • 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 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 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 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 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.

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.

@sashankaryal sashankaryal requested a review from a team October 24, 2024 16:31
@sashankaryal sashankaryal self-assigned this Oct 24, 2024
@sashankaryal sashankaryal added the bug Bug fixes label Oct 24, 2024
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: 2

🧹 Outside diff range and nitpick comments (1)
app/packages/plugins/src/externalize.ts (1)

Line range hint 1-68: Consider documenting the externalization strategy.

The current approach of selectively externalizing modules suggests there might be architectural constraints or patterns that should be documented. This would help future maintainers understand:

  1. Which modules can be safely externalized
  2. What conditions must be met for successful externalization
  3. Common pitfalls and their solutions

Consider creating a EXTERNALIZATION.md document in the project root to capture these learnings and guidelines.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 51d49e8 and a2ae06b.

⛔ Files ignored due to path filters (2)
  • app/packages/looker-3d/package.json is excluded by !**/*.json
  • app/yarn.lock is excluded by !**/yarn.lock, !**/*.lock, !**/*.lock
📒 Files selected for processing (2)
  • app/packages/looker-3d/src/index.ts (1 hunks)
  • app/packages/plugins/src/externalize.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/packages/looker-3d/src/index.ts
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/plugins/src/externalize.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (1)
app/packages/plugins/src/externalize.ts (1)

2-8: LGTM: Import changes align with externalization requirements.

The new imports are properly structured and follow consistent naming patterns.

Comment on lines +64 to +68
// todo: the following cannot be externalized because of unknown reason
// window.__fol3d__ = fol3d;
// window.__foe__ = foe;
// window.__fom__ = fom;
// window.__focore__ = focore;
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

Consider adding runtime checks for externalized dependencies.

Since some modules cannot be externalized, consider adding runtime checks to gracefully handle cases where plugins might attempt to access these unavailable modules.

Add defensive checks:

if (typeof window !== "undefined") {
+  const warnUnavailable = (module: string) => {
+    console.warn(`${module} is not available as an external dependency`);
+  };
+
   // existing assignments...
-  // window.__fol3d__ = fol3d;
+  Object.defineProperty(window, '__fol3d__', {
+    get() {
+      warnUnavailable('looker-3d');
+      return undefined;
+    }
+  });
   // Similar pattern for other unavailable modules
}

Committable suggestion was skipped due to low confidence.

Comment on lines +37 to +41
// todo: the following cannot be externalized because of unknown reason
// __focore__: typeof focore;
// __fol3d__: typeof fol3d;
// __fom__: typeof fom;
// __foe__: typeof foe;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Based on the analysis of the import patterns and dependencies, I can now provide a final response:

Externalization blockers likely due to internal package dependencies

The investigation reveals that these modules cannot be externalized due to complex interdependencies within the codebase:

  • @fiftyone/core is heavily imported across multiple packages and contains shared components
  • @fiftyone/looker-3d has bidirectional dependencies with core (e.g., core imports Looker3d component while looker-3d imports core components)
  • The modules are tightly coupled through direct imports of internal components (e.g., @fiftyone/core/src/plugins/SchemaIO/components/ButtonView)
  • There are deep imports accessing specific internal paths rather than public APIs

These patterns suggest that externalization would require significant refactoring to:

  1. Establish clear public APIs
  2. Remove direct imports of internal components
  3. Resolve the circular dependencies between packages
🔗 Analysis chain

Investigate root cause of externalization failures.

The TODO comments indicate systematic issues with specific modules (focore, fol3d, fom, foe). This could be related to circular dependencies or module resolution problems.

Let's check for potential circular dependencies:


Let me gather more specific information about the imports and dependencies between these modules.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential circular dependencies in problematic modules

# Search for cross-references between these modules
echo "Checking for cross-references between problematic modules..."
rg -l "@fiftyone/(core|looker-3d|map|embeddings)" --type ts

# Check import patterns
echo "Analyzing import patterns..."
ast-grep --pattern 'import * from "@fiftyone/$_"'

Length of output: 1169


Script:

#!/bin/bash
# Check for specific imports and dependencies between the problematic modules

# Look for direct imports of these modules
echo "Checking direct imports..."
rg "from ['\"]@fiftyone/(core|looker-3d|map|embeddings)" -B1 -A1

# Check for type references
echo -e "\nChecking type references..."
rg "type.*(@fiftyone/(core|looker-3d|map|embeddings))" --type ts

# Look for circular import patterns
echo -e "\nChecking for potential circular patterns..."
for module in core looker-3d map embeddings; do
  echo "=== Checking $module ==="
  rg "from.*@fiftyone/$module" app/packages/$module/
done

Length of output: 5409

Copy link
Contributor

@minhtuev minhtuev left a comment

Choose a reason for hiding this comment

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

👍

@sashankaryal sashankaryal merged commit 048d041 into develop Oct 24, 2024
11 checks passed
@sashankaryal sashankaryal deleted the fix/externalize-bug-build branch October 24, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants