troika icon indicating copy to clipboard operation
troika copied to clipboard

RangeError on build step

Open Hooman-studio opened this issue 1 year ago • 1 comments

I get the follow errors on production (I am using next.js) when I run next build:

Failure loading font http://localhost:3000/models/digital-7-mono.ttf; trying fallback RangeError: Offset is outside the bounds of the DataView
    at DataView.getUint16 (<anonymous>)
    etc...

Failure loading font https://fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxM.woff RangeError: Offset is outside the bounds of the DataView
    at DataView.getUint16 (<anonymous>)
    etc...

When running next dev this error doesn't come up.

-I am using troika-three-text via the drei <Text /> component. I found out this uses the preloadFont function as well, I am not sure that that is relevant, but just in case it is.

-Error happens both in Chrome and Safari.

Hooman-studio avatar Sep 22 '22 18:09 Hooman-studio

Do you have somewhere showing this bug in action that I could look at?

lojjic avatar Sep 22 '22 22:09 lojjic

Here's a reproducible example: https://stackblitz.com/edit/nextjs-fznkmq?file=package.json,next.config.js

I've narrowed it down to the options swcMinify and next version 12.3.1. Steps to reproduce:

  1. Set swcMinify: true in next.config.js.
  2. Run yarn && yarn next build && yarn next start.

The error is gone when swcMinify: false.

Another issue that manifested in different behaviours on prod and dev builds, which might be related, is https://github.com/pmndrs/react-three-fiber/issues/2533.

max-ch9i avatar Sep 27 '22 12:09 max-ch9i

Hmmm, I don't get that error when setting swcMinify: true and running that command in your stackblitz. Are there any additional steps needed?

lojjic avatar Sep 28 '22 03:09 lojjic

Tried that myself again and couldn't reproduce either. However, when I tried npx next build && npx next start instead, the error appeared again: Screenshot 2022-09-28 at 08 10 24

max-ch9i avatar Sep 28 '22 07:09 max-ch9i

Thanks, that worked to reproduce it.

It seems there is a bug in how swcMinify is rewriting the code. This seems to be the culprit:

image

That r < r + i loop condition is this in the original code:

offset < offset0 + length

It seems it's merging two separate variables (offset which is incremented and offset0 which remains static) into the same r variable...? That makes the condition always true and it would be an infinite loop if the DataView read didn't start throwing past the array length.

I'm not sure where to point you to get it fixed in the minifier.

lojjic avatar Sep 28 '22 16:09 lojjic

Thanks for debugging. I've referenced your find in this thread: https://github.com/vercel/next.js/discussions/30237#discussioncomment-3755143

max-ch9i avatar Sep 28 '22 16:09 max-ch9i

Seems like the issue is fixed on canary: https://github.com/vercel/next.js/discussions/30237#discussioncomment-3769166

max-ch9i avatar Sep 30 '22 08:09 max-ch9i

Great! I'm going to close this issue then. 🎉

lojjic avatar Oct 01 '22 03:10 lojjic