Skip to content

[Autocomplete] Ensure default plugins are nicely merged with user-defined plugins - #2841

Merged
Kocal merged 1 commit into
symfony:2.xfrom
Kocal:1128-auto-complete-get-url
Jun 14, 2025
Merged

Kocal merged 1 commit into
symfony:2.xfrom
Kocal:1128-auto-complete-get-url

Conversation

@Kocal

@Kocal Kocal commented Jun 13, 2025

Copy link
Copy Markdown
Member
Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #1128, Fix #2002
License MIT

The issue happens because when merging the default configuration and the configuration defined by the user, plugins defined by the users erase plugins defined in the default configuration:

At the moment, when the user didn't define tom_select_options.plugins, everything works fine:

Screenshot Capture d’écran 2025-06-13 à 14 22 37

But when configuring tom_select_options.plugins, some necessary plugins are missing:

Screenshot Capture d’écran 2025-06-13 à 14 22 55

With this PR, tom_select_options.plugins from the default configuration and the configuration defined by the user are nicely merged:

Screenshots Capture d’écran 2025-06-13 à 14 23 30 Capture d’écran 2025-06-13 à 14 23 53

TODO:

  • Update JS tests to prevent regressions

@carsonbot carsonbot added Autocomplete Bug Bug Fix Feature New Feature Status: Needs Review Needs to be reviewed labels Jun 13, 2025
@github-actions

github-actions Bot commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
Autocomplete
controller.js 16.7 kB / 3.96 kB 17.6 kB+5% 📈 / 4.12 kB+4% 📈

@Kocal Kocal removed the Feature New Feature label Jun 13, 2025
@Kocal
Kocal force-pushed the 1128-auto-complete-get-url branch 2 times, most recently from 93b1f34 to 6740a92 Compare June 13, 2025 15:38
expect(fetchMock.requests()[1].url).toEqual('/path/to/autocomplete?query=foo');
});

it('connect with ajax URL on a select element, even when the user define custom TomSelect plugins', async () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This test fails (as expected), when running on 2.x:

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Uncaught Exception ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: this.getUrl is not a function
 ❯ TomSelect.call src/controller.ts:264:34
    262|             // the 'this.XXX' calls inside this method fail
    263|             load: function (query: string, callback: TomLoadCallback) {
    264|                 const url = this.getUrl(query);
       |                                  ^
    265|                 fetch(url)
    266|                     .then((response) => response.json())
 ❯ Timeout._onTimeout ../../../node_modules/tom-select/src/utils.ts:59:7
 ❯ listOnTimeout node:internal/timers:594:17
 ❯ processTimers node:internal/timers:529:7

This error originated in "test/controller.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
The latest test that might've caused the error is "connect with ajax URL on a select element, even when the user defined custom TomSelect plugin". It might mean one of the following:
- The error was thrown, while Vitest was running this test.
- If the error occurred after the test had been completed, this was the last documented test before it was thrown.

@Kocal
Kocal force-pushed the 1128-auto-complete-get-url branch from 6740a92 to 9da1c09 Compare June 13, 2025 15:39
@Kocal
Kocal requested review from kbond and smnandre June 13, 2025 15:39
Comment on lines +333 to +336
plugins: {
...this.#normalizePluginsToHash(config1.plugins || {}),
...this.#normalizePluginsToHash(config2.plugins || {}),
},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Converting ['foo'] or [{ name: 'foo', options: {/* ... */} }] to { foo: {/* ... */} } helps us to merge the plugins configurations

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Jun 14, 2025
@Kocal
Kocal merged commit ae07fdc into symfony:2.x Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Autocomplete Bug Bug Fix Status: Reviewed Has been reviewed by a maintainer

Projects

None yet

3 participants