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

Stack overflow caused by large output #5614

Closed
6 tasks done
RobinClowers opened this issue Apr 24, 2024 · 10 comments
Closed
6 tasks done

Stack overflow caused by large output #5614

RobinClowers opened this issue Apr 24, 2024 · 10 comments
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@RobinClowers
Copy link

Describe the bug

This appears to be a regression of #3060. When an error occurs with a very large output (in my case from @testing-library/react), picocolors causes a stack overflow.

⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
RangeError: Maximum call stack size exceeded
 ❯ replaceClose node_modules/picocolors/picocolors.js:22:21
 ❯ replaceClose node_modules/picocolors/picocolors.js:25:30
 ❯ replaceClose node_modules/picocolors/picocolors.js:25:30
 ❯ replaceClose node_modules/picocolors/picocolors.js:25:30
 ❯ replaceClose node_modules/picocolors/picocolors.js:25:30
 ❯ replaceClose node_modules/picocolors/picocolors.js:25:30
 ❯ replaceClose node_modules/picocolors/picocolors.js:25:30
 ❯ replaceClose node_modules/picocolors/picocolors.js:25:30
 ❯ replaceClose node_modules/picocolors/picocolors.js:25:30

Reproduction

Unfortunately I don't have a reproduction handy. I suspect this would reproduce with RTL, a large dom and DEBUG_PRINT_LIMIT=100000 vitest.

System Info

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 5.56 GB / 64.00 GB
    Shell: 5.2.15 - /opt/homebrew/bin/bash
  Binaries:
    Node: 18.18.0 - ~/.volta/tools/image/node/18.18.0/bin/node
    Yarn: 1.22.17 - ~/.volta/tools/image/yarn/1.22.17/bin/yarn
    npm: 9.8.1 - ~/.volta/tools/image/node/18.18.0/bin/npm
  Browsers:
    Brave Browser: 121.1.62.156
    Chrome: 124.0.6367.62
    Chrome Canary: 121.0.6125.0
    Edge: 124.0.2478.51
    Firefox: 125.0.1
    Safari: 17.4.1
  npmPackages:
    vitest: ^1.5.0 => 1.5.0

Used Package Manager

yarn

Validations

@hi-ogawa
Copy link
Contributor

The linked issue #3060 seems related, but I'm not sure how to get the error considering the fix #3078 seems okay.

I tried something like this and still seems fine with DEBUG_PRINT_LIMIT=100000:

    const node = <div id="hey">
      {[...Array(5000)].map(i => <div key={i} id={i} style={{ color: "red" }}><span/></div>)}
    </div>
    render(node);
    screen.getByRole('no-such-thing') // testing-library throws an error
TestingLibraryElementError: Unable to find an accessible element with the role "no-such-thing"

There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the `hidden` option to `true`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole

Ignored nodes: comments, script, style
<body>
  <div>
    <div
      id="hey"
    >

Copy link

Hello @RobinClowers. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
@RobinClowers
Copy link
Author

Can I get this issue reopened? I've created a reproduction. Just yarn && yarn test should reproduce the bug (npm should work fine too). They key thing turns out to be CI=1, it seems like there is some code path that's only happening in CI that also needs the guard.

Let me know if I should open a new issue instead of reopening this one.

@hi-ogawa hi-ogawa reopened this May 9, 2024
@hi-ogawa hi-ogawa added p3-minor-bug An edge case that only affects very specific usage (priority) and removed needs reproduction pending triage labels May 9, 2024
@hi-ogawa
Copy link
Contributor

Confirmed the issue. Thanks for the reproduction 👍

@hi-ogawa
Copy link
Contributor

hi-ogawa commented May 10, 2024

It seems like call stack error is due to a specific implementation of picocolors and technically it can be avoided, so I raised an issue upstream alexeyraspopov/picocolors#63.

As upstream might not progress fast, Vitest can still fix this by patching picocolors or simply truncate the error message wherever this is happening.

Also the minimum repro is this:
https://stackblitz.com/edit/vitest-dev-vitest-858psz?file=test%2Frepro.test.ts

// CI=1 npm run test

import { test } from "vitest";

test("repro", () => {
  const x = "\x1b[34m" + "x" + "\x1b[39m"
  throw new Error(x.repeat(10000));
})

@alexeyraspopov
Copy link

The upstream issue is fixed and thanks @hi-ogawa for contribution. picocolors@1.0.1 is published and now should be more resilient to large colored outputs.

@RobinClowers
Copy link
Author

@hi-ogawa are you planning to bump the version in vitest? I'm happy to submit that PR if that's helpful.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented May 16, 2024

@RobinClowers picocolors is not bundled with vitest package, so you should be able to update the transitive dependency on your own. Depending on package manager, for example, pnpm dedupe would help.

I also confirmed the last reproduction is fixed with package.json overrdies
https://stackblitz.com/edit/vitest-dev-vitest-a3p1xh?file=package.json


Also picocolors bump is included in the next Renovate PR #5712, so it should come soon with the next release.

@RobinClowers
Copy link
Author

Yeah, I already updated my app, just wanted to make sure it would land here, sounds like the renovate PR has it covered!

@hi-ogawa
Copy link
Contributor

Cool, thanks for the reminder! As you confirmed it's working for you, I'll close this issue then.

I just remembered that Vitest has utilities which is mostly a copy of picocolors internally, so I'm updating that in a separate PR #5733.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

3 participants