Skip to content

fix: stale envFrameMap#3932

Merged
RichDom2185 merged 2 commits into
source-academy:masterfrom
Akshay-2007-1:master
Jun 2, 2026
Merged

fix: stale envFrameMap#3932
RichDom2185 merged 2 commits into
source-academy:masterfrom
Akshay-2007-1:master

Conversation

@Akshay-2007-1
Copy link
Copy Markdown
Contributor

Description

Closes #3127

Frame.envFrameMap is a static Map<string, Frame> that maps environment IDs to their rendered Frame objects. It was never cleared between steps, so stale Frame objects from previous render passes persisted in the map.

The symptom: FnValue.draw() calls Frame.getFrom(this.data.environment) to find the enclosing frame and draw an arrow to it. This lookup returned a Frame from an earlier step — one that applyFixedPositions() had never updated. The stale frame had its original computed _y (e.g. 215) while the current layout's frame had the correct cached _y (e.g. 240) after applyFixedPositions ran. So enclosingFrame pointed to a ghost frame at the wrong position, not the live one in the current layout.

Fix: call Frame.clearMap() at the top of initializeGrid() so the map is wiped before new Frame objects are registered for the current step. After this, FnValue.draw() always resolves enclosingFrame to the current step's Frame, which has had its coordinates correctly updated by applyFixedPositions.

Refer to the comment section here for how the debugging happened and a clearer understanding on what the bug actually is and what the cause of it actually is.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code quality improvements

How to test

function test_func() {
    const x = [];
    const a = d => d + 1;
    return a;
}

const result = test_func();
result(5);

To test and see how to use the Chrome dev tools along with the breakpoints feature, refer to the actual issue at #3127.

Checklist

  • I have tested this code
  • I have updated the documentation

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 13176ef0-cfe5-4341-8b96-d63d2c33b6ce

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR adds frame map clearing capability to the CSE machine layout system. The Frame component receives a new static clearMap() method that resets its internal environment-to-frame mapping cache. During grid initialization in CseMachineLayout, this method is imported and called to ensure a clean frame state before layout levels are rebuilt.

Changes

Frame map clearing during layout initialization

Layer / File(s) Summary
Frame map clearing method and integration
src/features/cseMachine/components/Frame.tsx, src/features/cseMachine/CseMachineLayout.tsx
Frame.clearMap() static method is defined to clear the envFrameMap, and is imported and invoked in Layout.initializeGrid before recomputing layout levels.

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: stale envFrameMap' directly and clearly summarizes the main bug fix: clearing stale entries from the envFrameMap static variable.
Description check ✅ Passed The description is comprehensive, explaining the bug, root cause, solution, testing approach, and linking to the issue. All key template sections are present and filled out.
Linked Issues check ✅ Passed The PR addresses the core objective of issue #3127 by clearing stale Frame objects before each layout initialization, ensuring Frame lookups resolve to current frames with correct coordinates.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the stale envFrameMap issue: adding clearMap() method and calling it during grid initialization as required.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a static clearMap method to the Frame component to clear the environment frame map, and integrates this call during the grid initialization in CseMachineLayout. The reviewer suggested updating the relative import of Frame to an absolute import starting with src/ to align with the repository's import guidelines.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/features/cseMachine/CseMachineLayout.tsx
Copy link
Copy Markdown
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@RichDom2185 RichDom2185 enabled auto-merge (squash) June 2, 2026 19:53
@RichDom2185 RichDom2185 merged commit aa50a79 into source-academy:master Jun 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

CSE Machine: FnValue does not actually refer to its enclosing environment

2 participants