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

Fixed ContextMenu Errors from issue 104 #142

Closed
wants to merge 0 commits into from

Conversation

tbytnar
Copy link
Contributor

@tbytnar tbytnar commented Oct 31, 2024

Type
What type of pull request is this? (e.g., Bug fix, Feature, Refactor, etc.)

  • Bug fix
  • Feature
  • Refactor
  • Other (please describe):

Description
Contextmenu error in console whenever a character sheet is reopened.

Related Issue
Closes #104

How Has This Been Tested?
Opening, closing, then reopening any character sheet any number of times. Since this symptom led from issues with Effects, Actions, and Equipment I also added several of each of these to character sheets and confirmed that they still render after my changes.

Screenshots (if applicable)
N/A

Checklist:

  • I have commented on my code, particularly in hard-to-understand areas.
  • My changes do not introduce any new warnings or errors.
  • My PR does not contain any copyrighted works that I do not have permission to use.
  • I have tested my changes on Foundry VTT version: 12.331.

Additional context
Delayed Initialization: Since the context menu setup now waits for rendering, any code that relies on the context menu being ready sooner might need to be adjusted, though I could not find anything that suggested this would be an issue..

Re-rendering Events: This hook will trigger only once per rendering cycle. I think this is okay, but would rather defer to someone with more expertise here. Are there any dynamic elements that might depend on this?

Copy link
Collaborator

@stanavdb stanavdb left a comment

Choose a reason for hiding this comment

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

Hey! thanks for the PR. I think there may be some missing commits? There's no change that actually triggers the hook?

In case there's no missing commits: The component system is not native to foundry, I built it as I didn't like the default handlebars application implementation. It doesn't have hooks, yet (practically everything in the system lacks hooks at this time).

However I think that regardless this isn't actually a solution. If you have a look at the context menu class, you can see that it binds to the component's render event. Meaning the context menu's render happens after the component's render already.

@stanavdb
Copy link
Collaborator

stanavdb commented Nov 1, 2024

Could you leave a comment on #104? That way I can assign you to the issue.

@tbytnar tbytnar mentioned this pull request Nov 1, 2024
1 task
@tbytnar
Copy link
Contributor Author

tbytnar commented Nov 2, 2024

Hey! thanks for the PR. I think there may be some missing commits? There's no change that actually triggers the hook?

In case there's no missing commits: The component system is not native to foundry, I built it as I didn't like the default handlebars application implementation. It doesn't have hooks, yet (practically everything in the system lacks hooks at this time).

However I think that regardless this isn't actually a solution. If you have a look at the context menu class, you can see that it binds to the component's render event. Meaning the context menu's render happens after the component's render already.

Ahhh, so all I've done is effectively disabled the context menus. Sorry I'm very new to this world and have a lot to learn.

@stanavdb
Copy link
Collaborator

stanavdb commented Nov 2, 2024

Ahhh, so all I've done is effectively disabled the context menus. Sorry I'm very new to this world and have a lot to learn.

No worries! Issue #104 isn't the easiest to pick up for anyone not familiar with the code base. Do you want me to unassign you from the issue, or do you want to keep working on it?

@tbytnar
Copy link
Contributor Author

tbytnar commented Nov 2, 2024

Keep me on it. This is how I learn. I'm a glutton for punishment.

I know the error messages stem from the create() method in AppContextMenu because the parent (AppContextMenu.Parent) being passed in doesn't have (an accessible) element. I have a workaround:

const checkElement = () => { if (this.element) { AppContextMenu.create( this as AppContextMenu.Parent, 'right', // (menu items here) ); } else if (attempts < 10) { attempts++; setTimeout(checkElement, 100); // Retry after 100ms } else { console.error("Failed to initialize AppContextMenu: element is not available."); } }; checkElement();

But I dont like it, has to be a better way and that's what I'm digging through now.

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.

Contextmenu error in console
2 participants