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

fix: code generate modal erroring out #4033

Merged

Conversation

AndrewBastin
Copy link
Member

Closes #4008

This PR fixes the issue where the Generate Code Modal errors out when opened.

What's Changed

The issue is mostly caused by ajv a dependency of httpsnippet (the library we use to power the Generate Code feature) not being kept properly up-to-date by the source package and needs to be pinned to an older version. We had this going in an earlier fix, but our fix was not solid, we just declared that httpsnippet has a peer dependency that is set to a specific version that works. But since its a peer dependency we are expected to have it installed as well. For some reason in pnpm v8, pnpm resolved it properly to load the version asked in peer dependencies, but this behaviour changed in v9. The fix here just adds ajv of the requested version added as a dependency to the users of httpsnippet so that pnpm resolves it correctly.

Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

Notes to reviewer

It is best to clear the node_modules and then running pnpm install before you spin up a dev server or a deploy instance as vite sometimes misses the changes.

# While cd-ed into the root of the repo
rm -rv node_modules packages/*/node_modules
pnpm install 

@AndrewBastin AndrewBastin requested a review from amk-dev as a code owner May 3, 2024 10:01
@AndrewBastin AndrewBastin changed the base branch from main to release/2024.3.3 May 3, 2024 10:01
Copy link
Contributor

@amk-dev amk-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add somemore context to the PR description.

Why this error occurred?

We encountered similar issues with httpsnippet package previously, and it was fixed in #3293.

we fixed it by adding ajv@6 to the peer dependencies of httpsnippet package. this worked because auto-install-peers was enabled by default. and the correct version of ajv was linked to the httpsnippet package.

Why is this breaking now?

PNPM 9 has a breaking change that allows pnpm to pick up other ranges of a dependency even if it is not matched by the peer dependency version. in our repo, some other packages like swagger-parser, nest-cli use ajv@8. so pnpm uses that version instead of again installing ajv@6.

this new behavior is causing the regression we are seeing now.

My suggestion:

I would say instead of adding the ajv@6 as a dep to hoppscotch/common. we could update the packageExtension to use dependencies instead of peerDependencies in the httpsnippet package. this way we can understand that this is a dependency of httpsnippet and not hoppscotch/common.

{
  "packageExtensions": {
    "[email protected]": {
      "dependencies": {
        "ajv": "6.12.3"
      }
    }
  }
}

let me know what you think. @AndrewBastin

@liyasthomas liyasthomas linked an issue May 6, 2024 that may be closed by this pull request
1 task
@AndrewBastin
Copy link
Member Author

Yep, makes sense to override ajv as a dependency. Will update the PR

@AndrewBastin AndrewBastin merged commit 4b8f3bd into hoppscotch:release/2024.3.3 May 6, 2024
1 check passed
@AndrewBastin AndrewBastin deleted the fix/codegen-break branch May 6, 2024 17:14
jobartim44 pushed a commit to jobartim44/hoppscotch-switch-workspace that referenced this pull request May 15, 2024
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.

[bug]: Something went wrong with </>show code [bug]: Selfhosted Generate Code ist Broken
3 participants