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

Add conditional loading for cross-fetch/polyfill - favour native fetch #1488

Merged
merged 5 commits into from
May 22, 2023

Conversation

icyJoseph
Copy link
Contributor

@icyJoseph icyJoseph commented May 9, 2023

Pull Request

Related issue

Fixes #1487

What does this PR do?

Load cross-fetch/polyfill only if fetch is undefined.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? Allow the SDK to use native fetch #1487 was opened by me though...
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

@bidoubiwa bidoubiwa added the enhancement New feature or request label May 16, 2023
@bidoubiwa
Copy link
Contributor

Hey @icyJoseph, you are right. Until v16 is end of life, we should keep the possibility to use the polyfill but since v18 is the latest node version, users shouldn't have to download the polyfill if they are in v18 and above.

I'm reviewing your PR soon :) I was on holiday. Thanks for your contribution btw 🙏

@bidoubiwa bidoubiwa self-requested a review May 17, 2023 09:52
@bidoubiwa
Copy link
Contributor

bidoubiwa commented May 17, 2023

Hey @icyJoseph, I was trying things out. I just realised that there is one file that I created that is not being ran by the CI (nor is it present in the package.json).

Could you try the following:

yarn build
cd tests/env/node
node getting_started.js

It raises the following error:

(node:43834) UnhandledPromiseRejectionWarning: ReferenceError: Response is not defined

If it's oke for you, could you update this line in the package.json:

    "test:env:nodejs": "node tests/env/node/index.js",

with

    "test:env:nodejs": "node tests/env/node/index.js && node tests/env/node/getting_started.js",

@icyJoseph
Copy link
Contributor Author

Right, so that's why the src/errors/meilisearch-communication-error.ts file imported the polyfill, I did not check if there was usage of Response, Request, or Headers, which are also typically polyfilled.

I'll see if there's a better place to conditionally load the polyfill.

@bidoubiwa
Copy link
Contributor

Thanks 🙏

@icyJoseph
Copy link
Contributor Author

I switch to requiring conditionally, and now I see this error:

class_1 [MeiliSearchApiError]: Attribute `id` is not filterable. Available filterable attributes are: `genres director`.
1:3 id >= 1

When running:

yarn build
cd tests/env/node
node getting_started.js

And then it fails with a 400 error

@bidoubiwa
Copy link
Contributor

bidoubiwa commented May 17, 2023

There is apparently an error in the getting_started.js file.

Could you change line 21 with:

  await index.updateFilterableAttributes([
    'director',
    'genres',
    'id'
  ])

I also realise that yarn build should be added in the package.json command to ensure it uses the latest umd build

"test:env:nodejs": "yarn build && node tests/env/node/index.js && node tests/env/node/getting_started.js",

@icyJoseph
Copy link
Contributor Author

Alright, I think it is looking good so far 😄

Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

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

LGTM ✨✨✨✨

Thanks a lot

@bidoubiwa
Copy link
Contributor

bors merge

@meili-bors
Copy link
Contributor

meili-bors bot commented May 22, 2023

Build succeeded:

@meili-bors meili-bors bot merged commit b319cc6 into meilisearch:main May 22, 2023
meili-bors bot added a commit that referenced this pull request May 29, 2023
1499: Remove conditionnal loading for fetch polyfill r=bidoubiwa a=bidoubiwa

Fixes: #1488 



Co-authored-by: Charlotte Vermandel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow the SDK to use native fetch
2 participants