Skip to content

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

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

Merged
merged 1 commit into from
Jun 14, 2025

Conversation

Kocal
Copy link
Member

@Kocal Kocal commented Jun 13, 2025

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
Copy link
Contributor

github-actions bot commented Jun 13, 2025

📊 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
@@ -138,6 +138,67 @@ describe('AutocompleteController', () => {
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
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
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
24 checks passed
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