Skip to content

feat: improve UX handling when multiple main files detected #1700

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nilayarya
Copy link

@nilayarya nilayarya commented Apr 5, 2025

Description of Change

Suggests UI changes to resolve #1508

  1. New MenuItem 'Set as Main Entry Point' available on right-click of valid main files (main.js, main.cjs, main.mjs)
  2. A Popup if there are multiple main files in the loaded fiddle (shows up only once a session )

Some gifs:

switchingsides


switcherooooo


showdialog

gist-url: https://gist.github.com/nilayarya/dfac02c9af5c699f3efc146ddf946f9f

CC @dsanders11

Checklist

  • PR description included and stakeholders cc'd
  • This PR was not created with AI. (PRs created mainly with AI will be closed. They waste our team's time. We ban repeat offenders.)
  • yarn test passes
  • tests are changed or added
  • PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, and past tense.

@nilayarya nilayarya requested review from codebytere and a team as code owners April 5, 2025 04:49
@coveralls
Copy link

Coverage Status

coverage: 87.482% (+0.01%) from 87.472%
when pulling 9c9e60d on nilayarya:multi-main
into d5e133f on electron:main.

Copy link
Member

@BlackHole1 BlackHole1 left a comment

Choose a reason for hiding this comment

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

Hi @nilayarya, thank you for your PR, but it seems to be incomplete. From the current PR, I can only temporarily consider this as an improvement for the edge case when there are multiple mainEntryPoints in the gist. When I create another mainEntryPoint from the left sidebar, it throws an error. According to the description in #1508, I believe @dsanders11 is hoping for a complete mainEntryPoint switching mechanism.

CleanShot 2025-07-23 at 11 21 01

const entryPoint = this.mainEntryPointFile();
if (isMainEntryPoint(id) && entryPoint) {
throw new Error(
`Cannot add file "${id}": Main entry point ${entryPoint} exists`,
);
}

Comment on lines +358 to +365
if (!this.mainEntryPoint || !this.files.get(this.mainEntryPoint)) {
const entryPoint = Array.from(this.files.keys()).find((id) =>
isMainEntryPoint(id),
);
if (entryPoint) this.mainEntryPoint = entryPoint;
return entryPoint;
}
return this.mainEntryPoint;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!this.mainEntryPoint || !this.files.get(this.mainEntryPoint)) {
const entryPoint = Array.from(this.files.keys()).find((id) =>
isMainEntryPoint(id),
);
if (entryPoint) this.mainEntryPoint = entryPoint;
return entryPoint;
}
return this.mainEntryPoint;
public mainEntryPointFile(): EditorId | null {
if (this.mainEntryPoint && this.files.get(this.mainEntryPoint)) {
return this.mainEntryPoint;
}
for (const [id] of this.files) {
if (isMainEntryPoint(id)) {
this.mainEntryPoint = id;
break;
}
}
return this.mainEntryPoint;

Make the code more intuitive and optimize performance a bit.

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.

Improve UX Handling if Multiple Main Files
3 participants