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

Codemirror: RangeError Selection points outside of document #505

Closed
danilowoz opened this issue Jun 20, 2022 · 4 comments
Closed

Codemirror: RangeError Selection points outside of document #505

danilowoz opened this issue Jun 20, 2022 · 4 comments

Comments

@danilowoz
Copy link
Member

Discussed in https://github.com/codesandbox/sandpack/discussions/501

Originally posted by grikomsn June 18, 2022
Recently migrated my Next.js side project from using sandpack v0 to v11 and noticed that for some reason it errors out in production but works on development. Below are screenshots with console logs for both instances.

Besides the console log errors, line numbers do not show and editor is not clickable nor editable. Will attempt debugging whether it's from the UI library or something else.

Development

image

Production

image

#465

Footnotes

  1. https://github.com/grikomsn/patterns-run/commit/51e7fd73145e37bff4667796793bf4e631f28e72#diff-55de525accdc1569db9c81113d77df271e051f7c8b9dc882d5268043346a18df

@danilowoz
Copy link
Member Author

danilowoz commented Jun 20, 2022

It seems that Nextjs is compiling the @codemirror/text with different outputs:

Wrong

// next.config.js
swcMinify: true,

// @codemirror/text
constructor(a, b=function(a) {
  for (let b of a)
    b.length;
  return -1
}

Correct

// next.config.js
swcMinify: false,

// @codemirror/text
constructor(a, b=function(a) {
  let e = -1
  for (let b of a)
    e + b.length + 1;
  return e
}

So, short answer, set swcMinify to false

🤯

@danilowoz
Copy link
Member Author

Hey @grikomsn, please take a look at the answer above, it might solve the problem. I'll try to address this issue with nextjs or swc.

@grikomsn
Copy link

Tried disabling swcMinify and it (surprisingly) works1. Thank you for the insight! Might need to reconsider enabling swcMinify for current and future projects.

Footnotes

  1. https://github.com/grikomsn/patterns-run/commit/b0ad10f8a2059913b8896aa82008b2c150178e30

@danilowoz
Copy link
Member Author

Addressed on vercel/next.js#36127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants