krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.89k stars 759 forks source link

Incorrect results in production build #500

Closed Haaxor1689 closed 3 years ago

Haaxor1689 commented 3 years ago

Describe the bug

I'm getting incorrect results in production build (CRA, react-scripts 3.4.3). When I check the same code in development build the issue is not present and it returns correct results. I've logged data that the Fuse instance is getting to see it on production and development and all of the searchKeys, options and inputValue are correct and are exactly the same between development and production.

In the provided example input value of jiho returns [Karlovarský kraj, Středočeský kraj] instead of [Jihočeský kraj, Jihomoravský kraj].

Version

6.4.1

🔬Minimal Reproduction

Here is the React code that handles select input's menu

const fuseFilter = useMemo(
    () =>
        new Fuse((options ?? []) as T[], {
            threshold: 0.4,
            keys: searchKeys,
        }),
    [options, searchKeys],
);
const filteredOptions = useMemo(
    () => fuseFilter.search(inputValue).map(i => i.item),
    [fuseFilter, inputValue, options, nameFromOption, unsorted],
);

Here is console logged data from production build

{
    "searchKeys": ["name"],
    "options": [
        {
            "id": "328a6206-109c-4aa5-8c43-f66fd348aa1c",
            "created": "2020-07-14T17:07:34.327Z",
            "updated": "2020-07-14T17:07:34.327Z",
            "name": "Hlavní město Praha",
            "active": true,
            "code": 19
        },
        {
            "id": "7e18df5b-6d83-4556-9dbb-fbd5afc61871",
            "created": "2020-07-14T17:07:34.386Z",
            "updated": "2020-07-14T17:07:34.386Z",
            "name": "Jihočeský kraj",
            "active": true,
            "code": 35
        },
        {
            "id": "25b0a921-d873-48f6-8037-c9f131a8765a",
            "created": "2020-07-14T17:07:34.393Z",
            "updated": "2020-07-14T17:07:34.393Z",
            "name": "Jihomoravský kraj",
            "active": true,
            "code": 116
        },
        {
            "id": "0a2c607e-031b-4b01-8e75-b0908ac062ec",
            "created": "2020-07-14T17:07:34.387Z",
            "updated": "2020-07-14T17:07:34.387Z",
            "name": "Karlovarský kraj",
            "active": true,
            "code": 51
        },
        {
            "id": "7368c5d0-d879-4abb-8c06-0d7554453446",
            "created": "2020-07-14T17:07:34.393Z",
            "updated": "2020-07-14T17:07:34.393Z",
            "name": "Kraj Vysočina",
            "active": true,
            "code": 108
        },
        {
            "id": "64945cbd-9a28-4dfb-9a69-426fdec4f9c7",
            "created": "2020-07-14T17:07:34.391Z",
            "updated": "2020-07-14T17:07:34.391Z",
            "name": "Královéhradecký kraj",
            "active": true,
            "code": 86
        },
        {
            "id": "ae53c569-18c1-48a7-89a0-ea8367e206b1",
            "created": "2020-07-14T17:07:34.391Z",
            "updated": "2020-07-14T17:07:34.391Z",
            "name": "Liberecký kraj",
            "active": true,
            "code": 78
        },
        {
            "id": "5562069d-f786-43c9-a6b4-a00b5f541c89",
            "created": "2020-07-14T17:07:34.394Z",
            "updated": "2020-07-14T17:07:34.394Z",
            "name": "Moravskoslezský kraj",
            "active": true,
            "code": 132
        },
        {
            "id": "1f1a01b8-5eb5-40b1-95b3-212b30ee1b2a",
            "created": "2020-07-14T17:07:34.394Z",
            "updated": "2020-07-14T17:07:34.394Z",
            "name": "Olomoucký kraj",
            "active": true,
            "code": 124
        },
        {
            "id": "1ac9daf7-dfb5-4891-a05a-0b96a4f160ba",
            "created": "2020-07-14T17:07:34.392Z",
            "updated": "2020-07-14T17:07:34.392Z",
            "name": "Pardubický kraj",
            "active": true,
            "code": 94
        },
        {
            "id": "af7fefa3-7944-4730-a6b3-01fb42b5a5dd",
            "created": "2020-07-14T17:07:34.387Z",
            "updated": "2020-07-14T17:07:34.387Z",
            "name": "Plzeňský kraj",
            "active": true,
            "code": 43
        },
        {
            "id": "1bcac5a3-5f44-4481-973d-e270cfa12e5c",
            "created": "2020-07-14T17:07:34.385Z",
            "updated": "2020-07-14T17:07:34.385Z",
            "name": "Středočeský kraj",
            "active": true,
            "code": 27
        },
        {
            "id": "b39de412-37de-4d35-b6cf-30a43394d02a",
            "created": "2020-07-14T17:07:34.390Z",
            "updated": "2020-07-14T17:07:34.390Z",
            "name": "Ústecký kraj",
            "active": true,
            "code": 60
        },
        {
            "id": "993fe1a6-7481-49f6-a55b-e861af133911",
            "created": "2020-07-14T17:07:34.395Z",
            "updated": "2020-07-14T17:07:34.395Z",
            "name": "Zlínský kraj",
            "active": true,
            "code": 141
        }
    ],
    "filteredOptions": [
        {
            "id": "0a2c607e-031b-4b01-8e75-b0908ac062ec",
            "created": "2020-07-14T17:07:34.387Z",
            "updated": "2020-07-14T17:07:34.387Z",
            "name": "Karlovarský kraj",
            "active": true,
            "code": 51
        },
        {
            "id": "1bcac5a3-5f44-4481-973d-e270cfa12e5c",
            "created": "2020-07-14T17:07:34.385Z",
            "updated": "2020-07-14T17:07:34.385Z",
            "name": "Středočeský kraj",
            "active": true,
            "code": 27
        }
    ],
    "inputValue": "jih",
    "fuseSearch": [
        {
            "item": {
                "id": "0a2c607e-031b-4b01-8e75-b0908ac062ec",
                "created": "2020-07-14T17:07:34.387Z",
                "updated": "2020-07-14T17:07:34.387Z",
                "name": "Karlovarský kraj",
                "active": true,
                "code": 51
            },
            "refIndex": 3
        },
        {
            "item": {
                "id": "1bcac5a3-5f44-4481-973d-e270cfa12e5c",
                "created": "2020-07-14T17:07:34.385Z",
                "updated": "2020-07-14T17:07:34.385Z",
                "name": "Středočeský kraj",
                "active": true,
                "code": 27
            },
            "refIndex": 11
        }
    ]
}

Additional context

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days