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

Importing svg's using svgr/webpack no longer works in the latest canary release when using ppr (error: Cannot read properties of undefined (reading 'stack')) #66137

Closed
sceppi opened this issue May 23, 2024 · 6 comments · Fixed by #67104
Labels
bug Issue was opened via the bug report template. locked Partial Prerendering (PPR) Related to Partial Prerendering. Webpack Related to Webpack with Next.js.

Comments

@sceppi
Copy link

sceppi commented May 23, 2024

Link to the code that reproduces this issue

https://github.com/sceppi/svgbug

To Reproduce

See example github code to reproduce.

  1. Create a new nextjs project enabling the experimental ppr:true
  2. import an svg into a page (make sure to have @svgr/webpack installed)
  3. run the project in development mode and going to the page results in error:
    TypeError: Cannot read properties of undefined (reading 'stack')
    at stringify ()
    at AsyncLocalStorage.run (node:async_hooks:346:14)
    digest: "2015626987"

Setting ppr to false resolves the error, so it is related to ppr
The issue only occurs when importing an svg. Just placing an svg directly in the code works fine

Current vs. Expected behavior

Importing an svg like this worked find in next 14.3.0-canary.70 (with ppr enabled) but no longer works in next 14.3.0-canary.79

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Enterprise
  Available memory (MB): 7789
  Available CPU cores: 8
Binaries:
  Node: 20.11.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.3.0-canary.79 // Latest available version is detected (14.3.0-canary.79).
  eslint-config-next: 14.3.0-canary.79
  react: 19.0.0-rc-f994737d14-20240522
  react-dom: 19.0.0-rc-f994737d14-20240522
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure, Webpack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Issue only occurs in development mode. It does not occur in Next 14.3.0-canary.70 but it occurs in 14.3.0-canary.79 (maybe also some earlier versions)

@sceppi sceppi added the bug Issue was opened via the bug report template. label May 23, 2024
@github-actions github-actions bot added the Webpack Related to Webpack with Next.js. label May 23, 2024
@ztanner ztanner added the Partial Prerendering (PPR) Related to Partial Prerendering. label May 23, 2024
@zamarawka
Copy link

Found that you could set 'use client' for component with svg usage and it become alive.

@kevva
Copy link
Contributor

kevva commented May 30, 2024

This was introduced in release https://github.com/vercel/next.js/releases/tag/v14.3.0-canary.77. Not sure which PR that is the culprit though.

@wyattjoh
Copy link
Member

Try this with the latest canary release, we've made some PPR updates since then and it may have been resolved.

@kevva
Copy link
Contributor

kevva commented Jun 17, 2024

@wyattjoh, in the latest version (15.0.0-canary.35) I'm getting this:

⨯ TypeError: Cannot read properties of undefined (reading 'split')
    at JSON.parse (<anonymous>)
    at JSON.parse (<anonymous>)
    at JSON.parse (<anonymous>)
    at JSON.parse (<anonymous>)

@kevva
Copy link
Contributor

kevva commented Jun 19, 2024

This is what the complete exception looks like:

Exception has occurred: TypeError: Cannot read properties of undefined (reading 'split')
  at buildFakeCallStack (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:3087:22)
    at createElement (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2191:25)
    at parseModelTuple (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2616:12)
    at Array.eval (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:3638:14)
    at JSON.parse (<anonymous>)
    at parseModel (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:3626:15)
    at initializeModelChunk (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2042:17)
    at getOutlinedModel (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2346:7)
    at parseModelString (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2602:18)
    at Array.eval (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:3634:14)
    at JSON.parse (<anonymous>)
    at parseModel (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:3626:15)
    at initializeModelChunk (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2042:17)
    at getOutlinedModel (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2346:7)
    at parseModelString (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2602:18)
    at Array.eval (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:3634:14)
    at JSON.parse (<anonymous>)
    at parseModel (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:3626:15)
    at initializeModelChunk (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2042:17)
    at getOutlinedModel (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2346:7)
    at parseModelString (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2602:18)
    at Array.eval (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:3634:14)
    at JSON.parse (<anonymous>)
    at parseModel (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:3626:15)
    at initializeModelChunk (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:2042:17)
    at readChunk (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-server-dom-webpack-experimental/cjs/react-server-dom-webpack-client.browser.development.js:1816:7)
    at callLazyInitInDEV (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:1042:10)
    at warnOnInvalidKey (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:12254:31)
    at reconcileChildrenArray (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:12288:21)
    at reconcileChildFibersImpl (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:12832:16)
    at reconcileChildFibers (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:12895:27)
    at reconcileChildren (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:18161:28)
    at updateFragment (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:18569:3)
    at beginWork (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:20651:14)
    at runWithFiberInDEV (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:1398:14)
    at performUnitOfWork (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:29173:14)
    at workLoopSync (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:28881:5)
    at renderRootSync (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:28836:7)
    at performConcurrentWorkOnRoot (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/react-dom-experimental/cjs/react-dom-client.development.js:27937:74)
    at workLoop (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/scheduler-experimental/cjs/scheduler.development.js:216:38)
    at flushWork (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/scheduler-experimental/cjs/scheduler.development.js:190:18)
    at MessagePort.performWorkUntilDeadline (webpack-internal:///(app-pages-browser)/../../node_modules/next/dist/compiled/scheduler-experimental/cjs/scheduler.development.js:441:25)

It's this line that's causing it because of the explicit null check. In our case stack is undefined. Asked why it was added here.

kevva referenced this issue in facebook/react Jun 19, 2024
…ks (#29632)

We have three kinds of stacks that we send in the RSC protocol:

- The stack trace where a replayed `console.log` was called on the
server.
- The JSX callsite that created a Server Component which then later
called another component.
- The JSX callsite that created a Host or Client Component.

These stack frames disappear in native stacks on the client since
they're executed on the server. This evals a fake file which only has
one call in it on the same line/column as the server. Then we call
through these fake modules to "replay" the callstack. We then replay the
`console.log` within this stack, or call `console.createTask` in this
stack to recreate the stack.

The main concern with this approach is the performance. It adds
significant cost to create all these eval:ed functions but it should
eventually balance out.

This doesn't yet apply source maps to these. With source maps it'll be
able to show the server source code when clicking the links.

I don't love how these appear.

- Because we haven't yet initialized the client module we don't have the
name of the client component we're about to render yet which leads to
the `<...>` task name.
- The `(async)` suffix Chrome adds is still a problem.
- The VMxxxx prefix is used to disambiguate which is noisy. Might be
helped by source maps.
- The continuation of the async stacks end up rooted somewhere in the
bootstrapping of the app. This might be ok when the bootstrapping ends
up ignore listed but it's kind of a problem that you can't clear the
async stack.

<img width="927" alt="Screenshot 2024-05-28 at 11 58 56 PM"
src="https://github.com/facebook/react/assets/63648/1c9d32ce-e671-47c8-9d18-9fab3bffabd0">

<img width="431" alt="Screenshot 2024-05-28 at 11 58 07 PM"
src="https://github.com/facebook/react/assets/63648/52f57518-bbed-400e-952d-6650835ac6b6">
<img width="327" alt="Screenshot 2024-05-28 at 11 58 31 PM"
src="https://github.com/facebook/react/assets/63648/d311a639-79a1-457f-9a46-4f3298d07e65">

<img width="817" alt="Screenshot 2024-05-28 at 11 59 12 PM"
src="https://github.com/facebook/react/assets/63648/3aefd356-acf4-4daa-bdbf-b8c8345f6d4b">
unstubbable added a commit to unstubbable/next.js that referenced this issue Jun 21, 2024
When using a custom webpack loader like `@svgr/webpack` to transform svg
files into React components, we need to make sure that these components
use the bundled React instance so that owner stacks are properly
defined. Otherwise, the React Flight Client would fail in
`buildFakeCallStack` with `[TypeError]: Cannot read properties of
undefined (reading 'split')`.

https://github.com/facebook/react/blob/57279287711cab628916ea7242055f89190aa47e/packages/react-client/src/ReactFlightClient.js#L1932

fixes vercel#66137
unstubbable added a commit to unstubbable/next.js that referenced this issue Jun 22, 2024
When using a custom webpack loader like `@svgr/webpack` to transform svg
files into React components, we need to make sure that these components
use the bundled React so that owner stacks are properly defined.
Otherwise, the React Flight Client would fail in `buildFakeCallStack`
with `[TypeError]: Cannot read properties of undefined (reading
'split')`.

https://github.com/facebook/react/blob/57279287711cab628916ea7242055f89190aa47e/packages/react-client/src/ReactFlightClient.js#L1932

fixes vercel#66137
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked Partial Prerendering (PPR) Related to Partial Prerendering. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants