sandpack icon indicating copy to clipboard operation
sandpack copied to clipboard

Console: export 'useId' was not found in 'react'

Open jodyheavener opened this issue 3 years ago • 0 comments

Bug report

Packages affected

  • [ ] sandpack-client
  • [x] sandpack-react

Description of the problem

In development, usage of React < v18 results in noisy console logging because we are accessing React.useId when it doesn't exist.

CleanShot 2022-09-15 at 16 44 18@2x

It's obfuscated, but I'm guessing it comes from this line: https://github.com/codesandbox/sandpack/blob/main/sandpack-react/src/components/CodeEditor/useGeneratedId.ts

Oddly enough, it's not actually being imported there, but the generated ESM converts it to that:

import{useId as rs,useRef as Vr}from"react";var ss=e=>typeof e=="string"?e:typeof rs=="function"?rs():Vr(ue()).current;

Not sure what the solution is... maybe replacing the line with something like "useId" in React would solve it? But I'm guessing it would still always convert to that import syntax.

What steps can we take to reproduce the problem?

  • Install @codesandbox/sandpack-react in a project with React 17.x
  • Render one of the package components
  • Open your developer console, observe output

Your Environment

Software Name/Version
Sandpack-react version 1.8.0

jodyheavener avatar Sep 15 '22 19:09 jodyheavener