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

Upgrade to next v14 #849

Merged
merged 2 commits into from
Apr 19, 2024
Merged

Upgrade to next v14 #849

merged 2 commits into from
Apr 19, 2024

Conversation

aspeddro
Copy link
Collaborator

@aspeddro aspeddro commented Apr 19, 2024

It looks like the problem is with JS minification. Fixed by disabling swcMinify in next.config.mjs

Compiled JS for CompilerManagerHook.Semver module

function parse(versionStr) {
  var parsePreRelease = function (str) {
    var match = str.split("-");
    if (match.length !== 2) {
      return ;
    }
    var identifier = match[1];
    var match$1 = identifier.split(".");
    if (match$1.length !== 2) {
      return ;
    }
    var name = match$1[0];
    var number = match$1[1];
    var buildIdentifier = Belt_Int.fromString(number);
    if (buildIdentifier === undefined) {
      return ;
    }
    switch (name) {
      case "alpha" :
          return {
                  TAG: "Alpha",
                  _0: buildIdentifier
                };
      case "beta" :
          return {
                  TAG: "Beta",
                  _0: buildIdentifier
                };
      case "dev" :
          return {
                  TAG: "Dev",
                  _0: buildIdentifier
                };
      case "rc" :
          return {
                  TAG: "Rc",
                  _0: buildIdentifier
                };
      default:
        return ;
    }
  };
  var isPrerelease = versionStr.search(/-/) !== -1;
  var versionNumber = Belt_Option.getWithDefault(Belt_Array.get(versionStr.split("-"), 0), versionStr);
  var match = versionNumber.replace("v", "").split(".");
  if (match.length !== 3) {
    return ;
  }
  var major = match[0];
  var minor = match[1];
  var patch = match[2];
  var match$1 = Belt_Int.fromString(major);
  var match$2 = Belt_Int.fromString(minor);
  var match$3 = Belt_Int.fromString(patch);
  if (match$1 === undefined) {
    return ;
  }
  if (match$2 === undefined) {
    return ;
  }
  if (match$3 === undefined) {
    return ;
  }
  var preReleaseIdentifier = isPrerelease ? parsePreRelease(versionStr) : undefined;
  return {
          major: match$1,
          minor: match$2,
          patch: match$3,
          preRelease: preReleaseIdentifier
        };
}

function toString(param) {
  var preRelease = param.preRelease;
  var mainVersion = "v" + String(param.major) + "." + String(param.minor) + "." + String(param.patch);
  if (preRelease === undefined) {
    return mainVersion;
  }
  var identifier;
  switch (preRelease.TAG) {
    case "Alpha" :
        identifier = "alpha." + String(preRelease._0);
        break;
    case "Beta" :
        identifier = "beta." + String(preRelease._0);
        break;
    case "Dev" :
        identifier = "dev." + String(preRelease._0);
        break;
    case "Rc" :
        identifier = "rc." + String(preRelease._0);
        break;
    
  }
  return mainVersion + "-" + identifier;
}

var Semver = {
  parse: parse,
  toString: toString
};

This is Semver module minified. Semver has two functions parse and toString.

var ea = {
            parse: function(e) {
                var n = -1 !== e.search(/-/)
                  , r = u.tj(s.U2(e.split("-"), 0), e).replace("v", "").split(".");
                if (3 === r.length) {
                    var t = r[0]
                      , o = r[1]
                      , i = r[2]
                      , a = b.m(t)
                      , c = b.m(o)
                      , l = b.m(i);
                    if (void 0 !== a && void 0 !== c && void 0 !== l)
                        return {
                            major: a,
                            minor: c,
                            patch: l,
                            preRelease: n ? function(e) {
                                var n = e.split("-");
                                if (2 === n.length) {
                                    var r = n[1].split(".");
                                    if (2 === r.length) {
                                        var t = r[0]
                                          , o = r[1]
                                          , i = b.m(o);
                                        if (void 0 !== i)
                                            switch (t) {
                                            case "alpha":
                                                return {
                                                    TAG: "Alpha",
                                                    _0: i
                                                };
                                            case "beta":
                                                return {
                                                    TAG: "Beta",
                                                    _0: i
                                                };
                                            case "dev":
                                                return {
                                                    TAG: "Dev",
                                                    _0: i
                                                };
                                            case "rc":
                                                return {
                                                    TAG: "Rc",
                                                    _0: i
                                                };
                                            default:
                                                return
                                            }
                                    }
                                }
                            }(e) : void 0
                        }
                }
            }
        };

See that the toString function is not in the ea object

We also have a getCompilerUrl function in CompilerManagerHook.res that uses CompilerManagerHook.Semver.toString

module CdnMeta = {
  let getCompilerUrl = (version): string =>
    `https://cdn.rescript-lang.org/${Semver.toString(version)}/compiler.js`

  let getLibraryCmijUrl = (version, libraryName: string): string =>
    `https://cdn.rescript-lang.org/${Semver.toString(version)}/${libraryName}/cmij.js`
}

The compiled js for getCompilerUrl below. See that it calls ei(e) which is the Semver.toString function

function es(e) {
            return "https://cdn.rescript-lang.org/" + ei(e) + "/compiler.js"
        }

Search for function ei we found the Semver.toString minified

image

But where Semver.toString is called to return a string it calls ea.toString, but toString does not exist in the object

https://github.com/rescript-association/rescript-lang.org/blob/e407ce1e72ecaabf7a52f2e4819c5b037123f43c/src/Playground.res#L989

image

Node example:

> var obj = {parse: "dummy"}
undefined
> obj.toString({major: 11, minor: 0, patch: 1, preRelease: undefined})
'[object Object]'
>

Related #844

Copy link

vercel bot commented Apr 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rescript-lang.org ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 19, 2024 3:22am

@aspeddro
Copy link
Collaborator Author

Next report a warning when disabling swcMinify

 ⚠ Disabling SWC Minifer will not be an option in the next major version. Please report any issues you m
ay be experiencing to https://github.com/vercel/next.js/issues

@fhammerschmidt
Copy link
Member

Great investigation. The deployment seems to work fine now, especially the playground. Let's merge this.

Do you know if that is a known issue in SWC?

@fhammerschmidt fhammerschmidt merged commit 840a322 into master Apr 19, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants