Visitar URL original
Fix create view modal submitting the request twice by SomSamantray · Pull Request #20552 · phpmyadmin/phpmyadmin · GitHub
Skip to content

Fix create view modal submitting the request twice - #20552

Open
SomSamantray wants to merge 1 commit into
phpmyadmin:masterfrom
SomSamantray:fix/18104-create-view-duplicate-click-handler
Open

SomSamantray wants to merge 1 commit into
phpmyadmin:masterfrom
SomSamantray:fix/18104-create-view-duplicate-click-handler

Conversation

@SomSamantray

Copy link
Copy Markdown

Description

Each time the create view dialog was opened, handleCreateViewModal() attached another click handler to #createViewModalGoButton. That button sits in the modal footer, which is rendered once per page and not replaced on each open. After the dialog had been opened a second time, one click on Go posted the create-view request twice.

This change removes the previous handler before binding a new one, so each submit sends one request.

Fixes #18104

Root cause: resources/js/modules/functions/handleCreateViewModal.ts binds to the static button on every open. The button is defined in resources/templates/modals/create_view.twig.

Known limitation, not changed here: two clicks on Go within a single open still each send a request, because the button is not disabled while a request is in flight. The issue's expected behaviour covers consecutive submissions across opens.

Testing

  • Added tests/javascript/modules/functions/handleCreateViewModal.test.ts. It opens the modal twice, clicks Go once, and expects one request to index.php?route=/view/create. On the original code it records two requests; with this change it records one.
  • npx jest: 4 suites, 6 tests pass.
  • eslint resources/js tests/javascript jest.config.cjs: clean.
  • Browser check not run: a phpMyAdmin server with PHP, Composer dependencies, and MySQL or MariaDB was not available in the environment where this change was prepared. A manual check would be to open Create view on a browse page, submit, reopen, submit again, and confirm one request per submit in the network panel.

Checklist

  • Read CONTRIBUTING.md.
  • Targets master. The bug is in the unreleased 6.0 line, and no QA_6_0 branch exists yet.
  • The commit has a Signed-off-by line (DCO).
  • The commit message is descriptive.
  • Single commit, no fixup commits.
  • The change is covered by a regression test.

AI assistance

This pull request was prepared with AI assistance (Claude Code, Claude Haiku 5.5). The author reviewed the diff and ran the tests listed above. CONTRIBUTING.md and the repository contain no AI contribution policy that applies to this change.

🤖 Generated with Claude Code

Each time the create view dialog was opened, handleCreateViewModal()
bound a new click handler to #createViewModalGoButton. That button is
in the modal footer, which is rendered once per page and not replaced
on each open, so after a second open a single click on Go posted the
create request twice.

Unbind the previous handler before binding the new one, and add a
regression test that opens the modal twice and expects one request.

Fixes phpmyadmin#18104

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Signed-off-by: Som Samantray <som.samantray@meritto.com>
@kamil-tekiela

Copy link
Copy Markdown
Contributor

@MauricioFauth Can't we just have delegated events and not worry about the on/off stuff?

@SomSamantray

Copy link
Copy Markdown
Author

Can't we just have delegated events and not worry about the on/off stuff?

I kept the .off('click').on('click', ...) in handleCreateViewModal for now:

  • The fix stays in the one function that opens the dialog, and the regression test covers exactly that path. A document-level delegated handler would be registered in event-loader.ts and removed in teardownFunctions, which spreads the change over two files and makes the test go through the page-load cycle.
  • The off is only there because each open re-binds the handler. It cannot double-bind, because the previous handler is removed before the new one is added.

Delegated events would fix the same bug. If you prefer that style, I can switch: bind $(document).on('click', '#createViewModalGoButton', ...) in onloadFunctions and remove it in teardownFunctions.

@kamil-tekiela

Copy link
Copy Markdown
Contributor

Submitting Claude generated fixes is ok, but please don't reply with Claude generated text to humans. Reading Claude's text is so nauseating.

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.

Create view button doesn't unbind jQuery events

3 participants