8000 fix: Replace explicit calls to refreshToolboxSelection with a workspace listener by RoboErikG · Pull Request #8980 · google/blockly · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Replace explicit calls to refreshToolboxSelection with a workspace listener #8980

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

Merged
merged 4 commits into from
May 6, 2025

Conversation

RoboErikG
Copy link
Contributor

The basics

The details

Resolves

Fixes #8975

Proposed Changes

Wraps the refreshToolbox calls in a setTimeout so they happen after the changes to variables finish.

Reason for Changes

We were ending up in an infinite recursion as the toolbox refreshed before the variables were fully created which then tried to create the variables again.

Test Coverage

Will need a follow-up PR to add tests for this.

Documentation

Additional Information

@RoboErikG RoboErikG requested a review from a team as a code owner May 2, 2025 21:13
@RoboErikG RoboErikG requested a review from gonfunko May 2, 2025 21:13
@RoboErikG RoboErikG added the issue: bug Describes why the code or behaviour is wrong label May 2, 2025
@RoboErikG RoboErikG enabled auto-merge (squash) May 5, 2025 16:28
@maribethb
Copy link
Contributor

Drive-by review: I don't love adding timeouts without a clear understanding of why they're needed. It seems like we didn't need them when the call was in workspace, so I don't understand what changed. My guess is it's needed due to the delay on events firing (though I don't know why that didn't apply before). If so, I wonder if a more straightforward approach would be to register an event listener for the various variable events that calls the refreshToolboxSelection method. That would let you just write the code once, ensure it's called no matter why the variable was renamed or whatever, and you wouldn't need a timeout since the work is definitely already done by the time the event fires.

@RoboErikG RoboErikG changed the title fix: Wrap toolbox refreshes in a timeout when modifying variables fix: Replace explicit calls to refreshToolboxSelection with a workspace listener May 5, 2025
@github-actions github-actions bot added the PR: fix Fixes a bug label May 5, 2025
@RoboErikG
Copy link
Contributor Author
RoboErikG commented May 5, 2025

Switching to the event listener seems to be working correctly and allowed me to remove additional calls to refreshToolboxSelection. Please double check my use of internal as I wasn't sure what scope the new callback function should have.

@gonfunko
Copy link
Contributor
gonfunko commented May 6, 2025

Rather than adding this to WorkspaceSvg, WDYT about updating the flyout's existing listener to listen for variable events and refresh itself? That seems like it might be a better division of responsibilities and would avoid adding yet another event listener.

@RoboErikG
Copy link
Contributor Author

@gonfunko Just tried that and it looks like the variable change events only get fired on the main workspace, not the flyout workspace, so I'd have to register a separate listener either way. It might be slightly more efficient to register a separate listener on the target listener in flyout.show and unregister it in hide, but it's also a bit more state to manage if I go that route.

What do you think?

@RoboErikG RoboErikG merged commit 04a31f9 into google:rc/v12.0.0 May 6, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Describes why the code or behaviour is wrong PR: fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

< 377E /include-fragment>
3 participants
0