Skip to content

Refactor admin JavaScript build system and structure#2464

Merged
Crabcyborg merged 20 commits into
masterfrom
feature/admin-js-webpack-refactor
Aug 25, 2025
Merged

Refactor admin JavaScript build system and structure#2464
Crabcyborg merged 20 commits into
masterfrom
feature/admin-js-webpack-refactor

Conversation

@shervElmi
Copy link
Copy Markdown
Contributor

@shervElmi shervElmi commented Aug 18, 2025

This PR modernizes the admin JavaScript codebase by:

Key Benefits

  • Minification & Optimization: The large formidable_admin.js file is now automatically minified and optimized through webpack's production build process
  • Modularization Foundation: Sets up the groundwork for breaking down the monolithic admin JavaScript into smaller, manageable modules

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 18, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Reworks build/lint config and admin bundling, updates admin style imports, applies widespread JavaScript formatting (many files), converts several IIFE wrappers to arrow IIFEs, and includes a small set of functional tweaks (doJsonPost fallback, class-counter guard fix, square frontend submit logic, applicationTemplates now returns void). Minor PHP reorder and new .browserslistrc added.

Changes

Cohort / File(s) Summary
Build & Lint
./.eslintignore, ./webpack.config.js, ./.browserslistrc
Added explicit eslint ignore entries for multiple js/*.js files including js/formidable_admin.js and several admin/vendor scripts; added webpack JS entry formidable_admin: './js/src/admin/admin.js'; added .browserslistrc extending @wordpress/browserslist-config.
Admin style imports & components
js/src/admin/styles.js, js/src/admin/components/*-style-component.js
Repointed admin style imports to ./components/*-style-component.js, added initHover() call in style options constructor; numerous small formatting changes across the component files.
Bundled/legacy module wrappers & exports
js/addons-page.js, js/formidable_blocks.js, js/formidable_styles.js, js/formidable_overlay.js, js/formidable_dashboard.js, js/formidable_admin_global.js, js/formidable.js
Many modules converted from classic IIFE/function expressions to arrow-function IIFEs and arrow helpers; in formidable_blocks.js the Ay export is now exposed via a getter-style export; mostly syntactic/packaging changes.
Admin JS & DOM utilities
js/admin/*.js, js/admin/dom.js, js/admin/embed.js, js/admin/style.js, js/admin/settings.js, js/admin/entries.js, js/admin/deactivation-feedback.js, js/admin/usage-tracking.js
Large set of whitespace/formatting and minor lint adjustments; functional change in doJsonPost to return json.data fallback when present; small getCookie signature formatting tweak.
Source (ESM) code formatting
js/src/** (many files under js/src/*)
Widespread stylistic edits (arrow param parentheses removal, spacing in template literals, JSDoc tweaks) across numerous source modules; most edits are non-functional formatting.
Functional fixes / small feature changes
js/src/components/class-counter.js, square/js/frontend.js, js/src/form-templates/elements/applicationTemplatesElement.js
Fix constructor guard precedence in counter class; square frontend: recompute card field validity and enable/disable submit dynamically; applicationTemplates: function no longer returns HTMLElement (now void).
Onboarding & packages
js/onboarding-wizard.js, js/src/onboarding-wizard/**, js/packages/floating-links/**
Wrapper refactor to arrow-IIFE in top-level onboarding file (scoping/initialization reorganized); many stylistic edits in onboarding source and floating-links package.
Stripe payment scripts
stripe/js/*.js, stripe/js/frmstrp.js, stripe/js/connect_settings.js
Mostly var→const/let scoping modernizations and formatting; some small behavior (slideOpts collapse branch added) and scoping improvements.
PHP minor
classes/controllers/FrmEntriesController.php
Moved global $frm_vars to top of hidden_columns, reordered local declarations and added docblock for remove_excess_cols; no behavioral change.
Cypress tests
tests/cypress/e2e/** (many files; notable heavy edits)
Numerous test files reformatted; some tests refactored with substantive flow changes (notably Applications/validateApplicationsPage.cy.js rework to grid-card pattern and Entries/deleteEntries.cy.js expanded to full create/submit/verify/delete lifecycle). Other tests primarily style/formatting updates.

Sequence Diagram(s)

(No sequence diagram provided — changes are mostly formatting, packaging, and small isolated logic tweaks; no single new control-flow feature to visualize.)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • validations for applications page #2023 — Touches tests/cypress/e2e/Applications/validateApplicationsPage.cy.js; strongly related due to large refactor of the same Applications test.
  • New Add-Ons Page #1802 — Modifies js/addons-page.js and related build/module changes; related to the bundling/wrapper edits and new webpack entry.
  • Prepare for v6.16.3 #2177 — Also touches js/formidable_blocks.js exports and packaging; related to the export/getter changes seen here.

Suggested reviewers

  • tuguirazvan
  • lauramekaj1

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/admin-js-webpack-refactor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
.eslintignore (1)

9-9: Use a glob for consistency and future-proofing.

Other generated bundles here use a recursive glob. Recommend switching to a double-star pattern so path changes or subdirectory outputs won't require another edit.

- js/formidable_admin.js
+ **/formidable_admin.js
webpack.config.js (1)

36-37: Confirm admin bundle enqueue; optionally externalize WP packages

We’ve verified that:

  • The entry file js/src/admin/admin.js exists.
  • In classes/controllers/FrmAppController.php:
    • wp_register_script( 'formidable_admin', ... '/js/formidable_admin.js', … ); (line 710)
    • wp_enqueue_script( 'formidable_admin' ); (line 738)

Optional: to avoid bundling WP packages imported by your admin code (e.g. @wordpress/i18n in styles.js), add them to sharedConfig.externals. For example:

--- webpack.config.js
@@ const sharedConfig = {
-  externals: {
-    jquery: 'jQuery',
-  },
+  externals: {
+    jquery: 'jQuery',
+    '@wordpress/i18n': [ 'wp', 'i18n' ],
+  },

This will let WordPress core provide the i18n module, reducing your bundle size.

js/src/admin/styles.js (2)

2-5: Good move to components/; consider centralizing exports to simplify imports.

As the components list grows, a barrel file reduces import noise and improves discoverability.

Apply this diff to consolidate imports:

-import frmRadioStyleComponent from './components/radio-style-component.js';
-import frmSliderStyleComponent from './components/slider-style-component.js';
-import frmTabsStyleComponent from './components/tabs-style-component.js';
-import frmStyleDependentUpdaterComponent from './components/dependent-updater-component.js';
+import {
+  frmRadioStyleComponent,
+  frmSliderStyleComponent,
+  frmTabsStyleComponent,
+  frmStyleDependentUpdaterComponent
+} from './components';

Then add js/src/admin/components/index.js with:

export { default as frmRadioStyleComponent } from './radio-style-component.js';
export { default as frmSliderStyleComponent } from './slider-style-component.js';
export { default as frmTabsStyleComponent } from './tabs-style-component.js';
export { default as frmStyleDependentUpdaterComponent } from './dependent-updater-component.js';

Also, because this file imports from @wordpress/i18n, ensure webpack treats it as an external (wp.i18n) to avoid bundling WP packages; see suggestion in webpack.config.js.


21-21: Nit: clarify the JSDoc sentence.

Small readability tweak.

- * Init the dependent
+ * Initialize the dependent updater components.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between eb5e404 and 26f2049.

📒 Files selected for processing (3)
  • .eslintignore (1 hunks)
  • js/src/admin/styles.js (2 hunks)
  • webpack.config.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: Cypress
  • GitHub Check: Cypress
  • GitHub Check: Cypress
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: Run PHP Syntax inspection (8.3)
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: PHP 8 tests in WP trunk
🔇 Additional comments (2)
webpack.config.js (1)

145-149: LGTM: dev-only source maps in CSS pipeline.

The css-loader options are correct for disabling url() handling and limiting source maps to development. No changes requested.

js/src/admin/styles.js (1)

2-5: All component import paths verified—no missing files
The sanity check confirms that each of the imported files in js/src/admin/styles.js exists under js/src/admin/components:

  • radio-style-component.js
  • slider-style-component.js
  • tabs-style-component.js
  • dependent-updater-component.js

No build failures expected from missing or mis-cased filenames.

@Crabcyborg Crabcyborg added this to the 6.24 milestone Aug 21, 2025
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg left a comment

Choose a reason for hiding this comment

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

@shervElmi We need to make sure the new file is being linted as well. I don't want more files that aren't getting validated.

It looks like I can add ./node_modules/.bin/eslint ./js/src/admin/admin.js to our jscs.yml, but if I try to add another file, like ./node_modules/.bin/eslint ./js/src/styles.js, it seems to have issues. I think because of the import lines.

I see this error instead:

Cannot find module '.../wp-content/plugins/formidable/node_modules/@wordpress/i18n/webpack.config.js

Could you help with fixing that?

@shervElmi
Copy link
Copy Markdown
Contributor Author

shervElmi commented Aug 21, 2025

@Crabcyborg how about linting all JS files in the js folder by changing the command to something like: (I'm not 100% sure on the exact syntax, but I’ll add the correct one.)

./node_modules/.bin/eslint ./js

We can then exclude the auto-generated files by adding them to .eslintignore.

Crabcyborg and others added 2 commits August 21, 2025 14:29
…checkboxes_when_limit_is_reached

Auto-disable screen options checkboxes when limit is reached
@Crabcyborg
Copy link
Copy Markdown
Contributor

Crabcyborg commented Aug 21, 2025

@shervElmi That sounds good, but since several files weren't being linted, it may not be super easy to do it all at once. There is likely code throwing errors.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
classes/controllers/FrmEntriesController.php (1)

448-452: Tighten docblock types for better static analysis

Specify the expected $atts shape, note pass-by-reference for $result, and declare the global used. This helps IDEs and tooling.

-	 *
-	 * @param array $atts
-	 * @param array $result
-	 * @return void
+	 * @param array{ i:int, max_columns:int, form_id:int } $atts
+	 * @param array<int,string> $result Passed by reference.
+	 * @global array $frm_vars
+	 * @return void
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 26f2049 and 192b46e.

⛔ Files ignored due to path filters (1)
  • .github/workflows/jscs.yml is excluded by !**/*.yml
📒 Files selected for processing (1)
  • classes/controllers/FrmEntriesController.php (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
classes/controllers/FrmEntriesController.php (1)
classes/models/FrmForm.php (2)
  • FrmForm (6-1269)
  • get_current_form_id (1082-1091)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cypress
🔇 Additional comments (1)
classes/controllers/FrmEntriesController.php (1)

396-407: LGTM on reordering globals and init; just verify call order assumption

Bringing global $frm_vars; and the $form_id/$hidden/$i init to the top reads cleaner and avoids any accidental late use. Functionally equivalent. One small caution: this relies on $frm_vars['cols'] having been populated by manage_columns() before this filter runs. That’s the normal WP List Table call order, but please smoke-test the Entries screen to confirm auto-hiding still kicks in when >11 columns exist (including subform/separate-value columns). If $frm_vars['cols'] isn’t set, your fallback ($i = 0) safely no-ops the auto-hide, which is acceptable.

- Convert var to let/const to fix no-var violations
- Remove unused variables to fix no-unused-vars errors
- Standardize JSDoc @returns to @return format
- Add ESLint disable comments for required jQuery usage
- Clean up formatting and code organization issues
- Add 'run analysis' label condition to jscs.yml workflow
- Follow same pattern as other workflows (cypress, phpunit, qadeploy)
- ESLint now runs on push to master or when PR has 'run analysis' label
- Enables manual control of when ESLint analysis runs on PRs
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg left a comment

Choose a reason for hiding this comment

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

Thanks @shervElmi!

I think we can merge this now.

🚀

@Crabcyborg Crabcyborg merged commit f12c3f1 into master Aug 25, 2025
14 of 15 checks passed
@Crabcyborg Crabcyborg deleted the feature/admin-js-webpack-refactor branch August 25, 2025 15:14
@coderabbitai coderabbitai Bot mentioned this pull request Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants