codesandbox / codesandbox/codesandbox-client

Code not logging out/running in expected order

Open
#5,908 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 Bug
Dominant language
JavaScript
Stars
13.6k
Forks
2.4k
Avg merge
6d 19h
Merged PRs (30d)
2

Description

🐛 bug report

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project
    adheres to.
  • I have searched the issue tracker for an issue that matches the one I want
    to file, without success.

Description of the problem

Console logging order not logging as expected.
Each log shows the result of functions that haven't yet been called.
i.e logging order should be:

log1 = []
call function
log2 = [value]
call fucntion
log3 = [value, value]

Instead it's returning

log1 = [value, value]
call function
log2 = [value, value]
call function
log3 = [value, value]
To Reproduce

I've run this code in multiple IDE's and works as expected elsewhere.

const array = [];

const addValueToArray = (arr) => {
  return arr.push(Math.floor(Math.random() * 5));
};

console.log(array); // empty array
addValueToArray(array);
console.log(array); // array with 1 random value
addValueToArray(array);
console.log(array); // array with two random values
Codesandbox
CleanShot 2021-06-17 at 10 55 18@2x
Codepen
CleanShot 2021-06-17 at 10 55 38@2x
Link to sandbox: link
Your Environment

Note when I originally I was on older Chrome version and CodeSandbox required updating, which i have since done to check the issue still exists.

Software Name/Version
Сodesandbox Not sure where to find, but latest version as I just updated
Browser Chrome 91.0.4472.106
Operating System macOS 11.3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the JavaScript reproduction from the issue in the linked CodeSandbox and compare its console output with the expected sequence. Trace how console logging is handled in the CodeSandbox client; done means each log reflects the array state at the point where console.log is called.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.