Skip to content

Commit

Permalink
fix(quantic): babel async await plugin setup added to fix quantic iss…
Browse files Browse the repository at this point in the history
…ue with firefox (#4620)

## [SFINT-5784](https://coveord.atlassian.net/browse/SFINT-5784)

continuation of @erocheleau 's work:
#4363

As @erocheleau  added in his PR: 

Salesforce LWS has a problem with static resources files using
async/await on Firefox, before this PR the search interface indefinitely
loads in Firefox when LWS is enabled.

This PR adds a script to use Babel to transform the headless.js files we
use to transform async to promises.

Add babel to quantic
Use babel plugin @babel/plugin-transform-async-to-generator to transform
built headless.js to transform async to promise.
Added this step prior to running the copy-static-resource in the nx
build script.

- Made sure this is still working correctly with Quantic and Headless
v3.
- Confirmed that the size of the Headless bundle after applying the
babel async await plugin is not significantly bigger.
- Confirmed that the search interface loads properly in Firefox.

### Before: 

https://github.com/user-attachments/assets/e6471fd9-d219-42ca-be93-05d2972e7937

### After:

https://github.com/user-attachments/assets/f5c880b0-c164-473d-88ad-3de62efd0bee

### Headless Size Before:
<img width="500" alt="Screenshot 2024-11-05 at 3 29 43 PM"
src="https://github.com/user-attachments/assets/371ecfa6-898c-4486-a97d-68dbc4b42f1f">

### Headless Size After:
<img width="500" alt="Screenshot 2024-11-05 at 3 29 59 PM"
src="https://github.com/user-attachments/assets/a71c0ba9-163c-48b3-a2c7-7a231ad6122a">





[SFINT-5784]:
https://coveord.atlassian.net/browse/SFINT-5784?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
mmitiche authored Nov 11, 2024
1 parent 0ebf951 commit ce8d7c8
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 7 deletions.
226 changes: 226 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/quantic/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["@babel/plugin-transform-async-to-generator"]
}
11 changes: 7 additions & 4 deletions packages/quantic/copy-static-resources.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {promisify} = require('util');
const ncp = promisify(require('ncp'));
const mkdir = promisify(require('fs').mkdir);
const rm = promisify(require('fs').rm);

const copy = async (source, dest) => {
try {
Expand Down Expand Up @@ -69,26 +70,28 @@ const copyHeadless = async () => {
{recursive: true}
);
await copy(
'../../node_modules/@coveo/headless/dist/quantic/headless.js',
'.tmp/quantic-compiled/headless.js',
'./force-app/main/default/staticresources/coveoheadless/headless.js'
);
await copy(
'../../node_modules/@coveo/headless/dist/quantic/case-assist/headless.js',
'.tmp/quantic-compiled/case-assist/headless.js',
'./force-app/main/default/staticresources/coveoheadless/case-assist/headless.js'
);
await copy(
'../../node_modules/@coveo/headless/dist/quantic/insight/headless.js',
'.tmp/quantic-compiled/insight/headless.js',
'./force-app/main/default/staticresources/coveoheadless/insight/headless.js'
);
await copy(
'../../node_modules/@coveo/headless/dist/quantic/recommendation/headless.js',
'.tmp/quantic-compiled/recommendation/headless.js',
'./force-app/main/default/staticresources/coveoheadless/recommendation/headless.js'
);
await copy(
'../../node_modules/@coveo/headless/dist/definitions',
'./force-app/main/default/staticresources/coveoheadless/definitions'
);

await rm('.tmp', {recursive: true});

console.info('Headless copied.');
};

Expand Down
7 changes: 5 additions & 2 deletions packages/quantic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"url": "git+https://github.com/coveo/ui-kit.git"
},
"scripts": {
"test": "npm run build:staticresources && npm run lint:check:tests && npm run validate:types && npm run test:unit",
"test": "npm run babel:headless && npm run build:staticresources && npm run lint:check:tests && npm run validate:types && npm run test:unit",
"lint:check:tests": "eslint force-app/main/default/lwc/ --format junit -o reports/eslint.xml",
"lint:fix": "npm run lint:fix:js",
"lint:fix:js": "eslint --fix force-app/main/default/lwc/ && eslint --fix force-app/examples/main/lwc/ && prettier \"force-app/{,**}/*.js\" --write",
Expand Down Expand Up @@ -42,7 +42,8 @@
"publish:bump": "npm run-script -w=@coveo/release bump",
"promote:npm:latest": "npm run-script -w=@coveo/release promote-npm-prod",
"preinstall": "node scripts/npm/check-sfdx-project.js",
"postinstall": "node scripts/npm/setup-quantic.js"
"postinstall": "node scripts/npm/setup-quantic.js",
"babel:headless": "babel ../../node_modules/@coveo/headless/dist/quantic --out-dir .tmp/quantic-compiled --extensions .js --minified"
},
"dependencies": {
"@coveo/bueno": "1.0.5",
Expand All @@ -54,6 +55,8 @@
"node": "^20.9.0 || ^22.11.0"
},
"devDependencies": {
"@babel/cli": "7.25.6",
"@babel/plugin-transform-async-to-generator": "7.24.7",
"@ckeditor/jsdoc-plugins": "39.9.1",
"@coveo/relay-event-types": "12.0.1",
"@coveo/release": "1.0.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/quantic/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
],
"executor": "nx:run-commands",
"options": {
"commands": ["npm run build:staticresources", "npm run build:doc"],
"commands": [
"npm run babel:headless && npm run build:staticresources",
"npm run build:doc"
],
"parallel": true,
"cwd": "packages/quantic"
}
Expand Down

0 comments on commit ce8d7c8

Please sign in to comment.