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(quantic): es build plugin added to allow rtk query to work inside salesforce #4731

Merged
merged 7 commits into from
Nov 29, 2024

Conversation

mmitiche
Copy link
Contributor

@mmitiche mmitiche commented Nov 27, 2024

SFINT-5831

The issue:

When submitting an evaluation from the Quantic Generated Answer in Salesforce the following issue occur preventing a successful request:

    at headless.js:30:99706
headless.js:18 TypeError: Failed to convert value to 'AbortSignal'.
    at https://data-ruby-6040-dev-ed.scratch.my.site.com/examples/resource/1732042845000/coveoheadless/headless.js:30:99706 Action dispatch error answer/executeMutation/rejected 
{type: 'answer/executeMutation/rejected', payload: undefined, meta: {…}, error: {…}}
error: 
message: "Failed to construct 'Request': Failed to read the 'signal' property from 'RequestInit': Failed to convert value to 'AbortSignal'."
name: "TypeError"stack: 
"TypeError: Failed to convert value to 'AbortSignal'.\n    at https://data-ruby-6040-dev-ed.scratch.my.site.com/examples/resource/1732042845000/coveoheadless/headless.js:30:99706"
"answer/executeMutation/rejected"

This is occurring because in Salesforce the AbortController/AbortSignal web API are not available and supported, so we are using a pony-fill that we are injecting in the headless bundle built for Quantic and Salesforce.

The problem is that Redux Toolkit Query does not seem to like this ponyfill and throws an error when starting to deal with it:

Screen.Recording.2024-11-28.at.8.28.31.AM.mov

To address this issue, we can avoid passing the Abort Signal to fetchBaseQuery which is the function provided by RTK Query and that is executed to fetch for the Answer API in answer-slice.ts .
But to make sure this fix only impacts Salesforce and the Headless bundle used for Quantic, I added an es build plugin that will do a small modification to the answer-slice.ts when building, instead of calling fetchBaseQuery like this:

    const data = fetchBaseQuery({
      baseUrl: `${platformEndpoint}/rest/organizations/${organizationId}/answer/v1/configs/${answerConfigurationId}`,
    })(updatedArgs, api, extraOptions);

it will be called like the following:

    const data = fetchBaseQuery({
      baseUrl: `${platformEndpoint}/rest/organizations/${organizationId}/answer/v1/configs/${answerConfigurationId}`,
    })(updatedArgs, {...api, signal: null}, extraOptions);

to allow properly submitting evaluations in Salesforce:

Screen.Recording.2024-11-28.at.8.07.53.AM.mov

Copy link

github-actions bot commented Nov 27, 2024

Pull Request Report

PR Title

✅ Title follows the conventional commit spec.

Live demo links

Bundle Size

File Old (kb) New (kb) Change (%)
case-assist 242.6 242.6 0
commerce 347.3 347.3 0
search 413.8 413.8 0
insight 404.9 404.9 0
recommendation 254.9 254.9 0
ssr 407.3 407.3 0
ssr-commerce 362.3 362.3 0

SSR Progress

Use case SSR (#) CSR (#) Progress (%)
search 39 44 89
recommendation 0 4 0
case-assist 0 6 0
insight 0 27 0
commerce 0 15 0
Detailed logs search : buildInteractiveResult
search : buildInteractiveInstantResult
search : buildInteractiveRecentResult
search : buildInteractiveCitation
search : buildGeneratedAnswer
recommendation : missing SSR support
case-assist : missing SSR support
insight : missing SSR support
commerce : missing SSR support

@mmitiche mmitiche changed the title fix(quantic): queryFn passed to the answer evaluation endpoint to fix abort signal issue in Salesforce fix(quantic): es build plugin added to allow rtk query to work inside salesforce Nov 28, 2024
@mmitiche mmitiche marked this pull request as ready for review November 28, 2024 13:45
@mmitiche mmitiche requested review from a team as code owners November 28, 2024 13:45
Copy link
Contributor

@alexprudhomme alexprudhomme left a comment

Choose a reason for hiding this comment

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

Thanks for the great explanation

Copy link
Contributor

@SimonMilord SimonMilord left a comment

Choose a reason for hiding this comment

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

Nice!

@dmgauthier
Copy link
Contributor

Very wise!

@mmitiche mmitiche added this pull request to the merge queue Nov 29, 2024
Merged via the queue into master with commit c80badf Nov 29, 2024
122 checks passed
@mmitiche mmitiche deleted the SFINT-5831 branch November 29, 2024 19:45
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.

4 participants