Skip to content

Fix a possible infinite loading in 3rd party integration #60196

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

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from

Conversation

lysyjan
Copy link
Contributor

@lysyjan lysyjan commented Aug 4, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

  • There was a possible infinite loading in the 3rd party implementation, as is MailPoet. This PR uses an unused parameter to avoid caching, causing endless loading.
  • A new middleware can prevent the status from being changed to "publish" when saving. This was also a problem in MailPoet when the post status was changed to "publish" during saving, which could override the "sent" or "draft" status.
  • Adjust the logic for displaying the original "Publish/Save" buttons, which didn't work correctly in some cases.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Enable the block-based email editor from WooCommerce → Settings → Advanced → Features → Block Email Editor (alpha)
  2. Open an email in the editor WooCommerce → Settings → Emails
  3. Verify functionality of the email editor
  4. Check that the save button works correctly

Testing that has already taken place:

  • I tested all fixes in the MailPoet integration.
  • I tried the email editor in the Woo plugin.

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

@lysyjan lysyjan added Ballade Issues related to block-based email editor package: @woocommerce/email-editor issues related to the @woocommerce/email-editor package labels Aug 4, 2025
Copy link
Contributor

github-actions bot commented Aug 4, 2025

Size Change: +2.86 kB (+0.05%)

Total Size: 5.92 MB

Filename Size Change
./plugins/woocommerce/client/blocks/build/featured-category.js 15 kB +573 B (+3.98%)
./plugins/woocommerce/client/blocks/build/featured-product.js 15.1 kB +557 B (+3.84%)
./plugins/woocommerce/client/blocks/build/woocommerce/product-collection.js 1.43 kB +324 B (+29.4%) 🚨

compressed-size-action

Copy link
Contributor

coderabbitai bot commented Aug 4, 2025

📝 Walkthrough

Walkthrough

This update addresses issues in the email editor, including fixing infinite template loading, refining the logic for displaying the publish button, and adding middleware to strip post status on save when configured. It also introduces a new export for the store name and adjusts how template queries are constructed in selectors.

Changes

Cohort / File(s) Change Summary
Email Editor Template Loading Fixes
packages/js/email-editor/changelog/fix-email-editor-template-loading
Adds a changelog entry documenting a patch that prevents email templates from loading indefinitely when editing emails.
Template Selector Query Update
packages/js/email-editor/src/store/selectors.ts
Refactors the getEditedPostTemplate selector to use a constructed query object with explicit parameters, including a cache-busting parameter, when fetching templates.
Publish Button Logic Refactor
packages/js/email-editor/src/hacks/publish-save.tsx
Refactors logic in the PublishSave component to determine when to show the original publish button, removing draft post exclusions and introducing a template edit flag. Updates comments and simplifies conditions.
Middleware for Post Status Stripping
packages/js/email-editor/changelog/add-middleware-to-strip-post-status-on-save
Adds a changelog entry for middleware that strips the post status from save data when a configuration flag is enabled, ensuring post status is removed during save if configured.
Export Store Name
packages/js/email-editor/src/index.ts
Adds an export for storeName from the store module with a descriptive JSDoc comment. No other code changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant EmailEditor
    participant Store
    participant Middleware

    User->>EmailEditor: Edit email template
    EmailEditor->>Store: Fetch templates with query (context, per_page, _woocommerce_email_editor)
    Store-->>EmailEditor: Return templates (no infinite loading)
    User->>EmailEditor: Save post
    EmailEditor->>Middleware: On save, check strip_post_status_on_save
    alt Config enabled
        Middleware->>EmailEditor: Strip post status from save data
    else Config disabled
        Middleware->>EmailEditor: Save data unchanged
    end
    User->>EmailEditor: Attempt to publish
    EmailEditor->>EmailEditor: Determine if publish button is shown (based on new logic)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e70d818 and 53a9079.

📒 Files selected for processing (2)
  • packages/js/email-editor/src/index.ts (1 hunks)
  • packages/js/email-editor/src/store/selectors.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/js/email-editor/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/js/email-editor/src/store/selectors.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-email-editor-template-loading

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
  • 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 src/utils.ts and explain its main purpose.
    • @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 comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

Documentation and Community

  • 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
Contributor

github-actions bot commented Aug 4, 2025

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@lysyjan lysyjan self-assigned this Aug 4, 2025
lysyjan added 2 commits August 6, 2025 09:38
Loading templates without the post_type parameter caused failing initialization in the MailPoet plugin.
@lysyjan lysyjan force-pushed the fix-email-editor-template-loading branch from bd784cb to 7efbc10 Compare August 6, 2025 07:38
Copy link
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: 3

🧹 Nitpick comments (1)
packages/js/email-editor/src/middleware/save-post-status.ts (1)

25-88: Add TypeScript types for better type safety.

The middleware lacks proper TypeScript types, which makes it harder to catch potential issues.

Add proper types at the top of the file:

interface RegistryDispatch {
    [storeName: string]: {
        [actionName: string]: ( ...args: any[] ) => Promise<any>;
    };
}

interface SaveEntityRecordArgs {
    kind: string;
    name: string;
    recordOrId: Record<string, any> | string | number;
    options?: Record<string, any>;
}

Then use these types in the middleware implementation for better type safety.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd784cb and 7efbc10.

📒 Files selected for processing (8)
  • packages/js/email-editor/changelog/fix-email-editor-template-loading (1 hunks)
  • packages/js/email-editor/src/editor.tsx (2 hunks)
  • packages/js/email-editor/src/global.d.ts (1 hunks)
  • packages/js/email-editor/src/hacks/publish-save.tsx (1 hunks)
  • packages/js/email-editor/src/middleware/save-post-status.ts (1 hunks)
  • packages/js/email-editor/src/store/initial-state.ts (1 hunks)
  • packages/js/email-editor/src/store/selectors.ts (2 hunks)
  • packages/js/email-editor/src/store/types.ts (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • packages/js/email-editor/src/store/types.ts
  • packages/js/email-editor/src/global.d.ts
  • packages/js/email-editor/src/editor.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/js/email-editor/changelog/fix-email-editor-template-loading
  • packages/js/email-editor/src/store/selectors.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)

**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable

Files:

  • packages/js/email-editor/src/store/initial-state.ts
  • packages/js/email-editor/src/middleware/save-post-status.ts
  • packages/js/email-editor/src/hacks/publish-save.tsx
**/*.{php,js,ts,jsx,tsx}

⚙️ CodeRabbit Configuration File

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

Files:

  • packages/js/email-editor/src/store/initial-state.ts
  • packages/js/email-editor/src/middleware/save-post-status.ts
  • packages/js/email-editor/src/hacks/publish-save.tsx
🧠 Learnings (10)
📚 Learning: in woocommerce email editor store initialization (packages/js/email-editor/src/store/initial-state.t...
Learnt from: triple0t
PR: woocommerce/woocommerce#59186
File: packages/js/email-editor/src/store/initial-state.ts:9-10
Timestamp: 2025-06-26T12:13:32.062Z
Learning: In WooCommerce email editor store initialization (packages/js/email-editor/src/store/initial-state.ts), the current_post_id and current_post_type from window.WooCommerceEmailEditor are required parameters that should cause explicit errors if missing, rather than using fallback values or optional chaining. The design preference is to fail fast when critical initialization data is unavailable.

Applied to files:

  • packages/js/email-editor/src/store/initial-state.ts
  • packages/js/email-editor/src/middleware/save-post-status.ts
  • packages/js/email-editor/src/hacks/publish-save.tsx
📚 Learning: in woocommerce email editor (packages/js/email-editor/src/hacks/publish-save.tsx), the currentpost o...
Learnt from: lysyjan
PR: woocommerce/woocommerce#59931
File: packages/js/email-editor/src/hacks/publish-save.tsx:0-0
Timestamp: 2025-07-23T14:53:29.447Z
Learning: In WooCommerce email editor (packages/js/email-editor/src/hacks/publish-save.tsx), the currentPost obtained from select(editorStore).getCurrentPost() is guaranteed to always be a post object, so null safety checks are not required when accessing its properties like status.

Applied to files:

  • packages/js/email-editor/src/store/initial-state.ts
  • packages/js/email-editor/src/middleware/save-post-status.ts
  • packages/js/email-editor/src/hacks/publish-save.tsx
📚 Learning: the displaystyleswitcher component in plugins/woocommerce/client/blocks/assets/js/blocks/product-fil...
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59900
File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/attribute-filter/inspector.tsx:0-0
Timestamp: 2025-07-24T05:37:00.907Z
Learning: The DisplayStyleSwitcher component in plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/components/display-style-switcher/index.tsx has been updated so that its onChange prop accepts only a string type (not string | number | undefined), eliminating the need for type assertions when using this component.

Applied to files:

  • packages/js/email-editor/src/store/initial-state.ts
  • packages/js/email-editor/src/hacks/publish-save.tsx
📚 Learning: in plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-addres...
Learnt from: ralucaStan
PR: woocommerce/woocommerce#58782
File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/customer-address.tsx:76-90
Timestamp: 2025-06-13T13:37:35.793Z
Learning: In plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/customer-address.tsx, the `shouldAnimate` flag is expected to be `false` only on initial render and may remain `true` after the first edit; it does not need to be reset.

Applied to files:

  • packages/js/email-editor/src/store/initial-state.ts
  • packages/js/email-editor/src/hacks/publish-save.tsx
📚 Learning: in woocommerce blocks typescript code, avoid type assertions (`as`) when accessing properties from u...
Learnt from: gigitux
PR: woocommerce/woocommerce#59659
File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/frontend.ts:136-147
Timestamp: 2025-07-22T09:30:43.528Z
Learning: In WooCommerce blocks TypeScript code, avoid type assertions (`as`) when accessing properties from unified stores. Instead, create proper union types that combine all the different store component types using `Partial<>` wrappers, and export the unified type to help third-party extenders. For example: `type UnifiedStore = BaseStore & Partial<StoreA> & Partial<StoreB>`.

Applied to files:

  • packages/js/email-editor/src/store/initial-state.ts
📚 Learning: in woocommerce mini cart implementation, the cart state is server-populated before javascript initia...
Learnt from: samueljseay
PR: woocommerce/woocommerce#58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:78-96
Timestamp: 2025-06-18T06:05:25.472Z
Learning: In WooCommerce mini cart implementation, the cart state is server-populated before JavaScript initialization, so wooStoreState.cart and wooStoreState.cart.totals will be available on first render without requiring null-safe guards.

Applied to files:

  • packages/js/email-editor/src/store/initial-state.ts
📚 Learning: in woocommerce payments onboarding components (like plugins/woocommerce/client/admin/client/settings...
Learnt from: vladolaru
PR: woocommerce/woocommerce#59160
File: plugins/woocommerce/client/admin/client/settings-payments/onboarding/providers/woopayments/steps/payment-methods-selection/index.tsx:0-0
Timestamp: 2025-06-26T14:56:54.917Z
Learning: In WooCommerce payments onboarding components (like plugins/woocommerce/client/admin/client/settings-payments/onboarding/providers/woopayments/steps/payment-methods-selection/index.tsx), when updating local React state based on API calls, the local state should only be updated after the API call succeeds to prevent inconsistent state if the save operation fails. The pattern is to move setPaymentMethodsState calls inside the .then() callback of the API promise.

Applied to files:

  • packages/js/email-editor/src/store/initial-state.ts
📚 Learning: for woocommerce mini-cart blocks in plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/, t...
Learnt from: samueljseay
PR: woocommerce/woocommerce#59051
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/index.tsx:66-70
Timestamp: 2025-06-23T05:47:52.696Z
Learning: For WooCommerce mini-cart blocks in plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/, the standardized conditional pattern for experimental features should be `if ( isExperimentalMiniCartEnabled() ) { blockSettings.save = () => <InnerBlocks.Content />; }` - defaulting to the traditional Save component and only overriding when the experimental feature is enabled.

Applied to files:

  • packages/js/email-editor/src/store/initial-state.ts
  • packages/js/email-editor/src/hacks/publish-save.tsx
📚 Learning: the wordpress editor store's getcurrentpost() method can return null or undefined in several edge ca...
Learnt from: lysyjan
PR: woocommerce/woocommerce#59931
File: packages/js/email-editor/src/hacks/publish-save.tsx:43-53
Timestamp: 2025-07-23T14:53:30.525Z
Learning: The WordPress editor store's getCurrentPost() method can return null or undefined in several edge cases: during initial load before post data is fetched, when there's no post context, for new unsaved posts, and during API errors. The official WordPress documentation specifically recommends checking for nullish values before accessing properties to avoid runtime errors. Robust null/undefined handling is required for plugins using this selector.

Applied to files:

  • packages/js/email-editor/src/store/initial-state.ts
  • packages/js/email-editor/src/hacks/publish-save.tsx
📚 Learning: in woocommerce block edit components (like plugins/woocommerce/client/blocks/assets/js/blocks/next-p...
Learnt from: kmanijak
PR: woocommerce/woocommerce#60154
File: plugins/woocommerce/client/blocks/assets/js/blocks/next-previous-buttons/edit.tsx:80-80
Timestamp: 2025-08-04T11:58:34.139Z
Learning: In WooCommerce block Edit components (like plugins/woocommerce/client/blocks/assets/js/blocks/next-previous-buttons/edit.tsx), buttons are preview/display elements for the block editor interface and are not meant to be interactive, so accessibility attributes like ARIA labels are not necessary for these non-functional preview buttons.

Applied to files:

  • packages/js/email-editor/src/hacks/publish-save.tsx
⏰ 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: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
  • GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: JavaScript - @woocommerce/admin-library [unit]
  • GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Check Asset Sizes
  • GitHub Check: build
🔇 Additional comments (3)
packages/js/email-editor/src/store/initial-state.ts (1)

33-34: LGTM - Optional chaining is appropriate for feature flags.

The use of optional chaining for strip_post_status_on_save is appropriate since this appears to be a feature flag with a reasonable default behavior (undefined/false means don't strip post status), unlike core required parameters that should fail fast.

packages/js/email-editor/src/hacks/publish-save.tsx (2)

43-55: Improved logic simplification.

The refactor to use isEditingTemplate based on post type instead of checking the current post object is a good improvement. This approach is more direct and avoids potential null/undefined issues with getCurrentPost().


57-68: Clear and well-documented condition logic.

The updated comments clearly explain when the original publish button should and shouldn't be displayed. The simplified condition logic is much more readable than the previous implementation.

lysyjan added 3 commits August 6, 2025 11:49
This can cause an issue in MailPoet when click on save publishes the email post.
Adjust conditions to ensure proper handling of template edits, post entity changes, and draft states.
@lysyjan lysyjan force-pushed the fix-email-editor-template-loading branch from 7efbc10 to 6dc9d71 Compare August 6, 2025 09:49
Copy link
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: 2

🧹 Nitpick comments (1)
packages/js/email-editor/src/middleware/strip-post-status-on-save.ts (1)

14-14: Use WeakMap to prevent memory leaks

The global originalActions object could potentially cause memory leaks if stores are dynamically created and destroyed. Consider using a WeakMap instead.

-const originalActions = {};
+const originalActions = new WeakMap();

Note: You'll need to update the corresponding access patterns throughout the file to use WeakMap methods.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7efbc10 and 6dc9d71.

📒 Files selected for processing (8)
  • packages/js/email-editor/changelog/add-middleware-to-strip-post-status-on-save (1 hunks)
  • packages/js/email-editor/src/editor.tsx (2 hunks)
  • packages/js/email-editor/src/global.d.ts (1 hunks)
  • packages/js/email-editor/src/hacks/publish-save.tsx (1 hunks)
  • packages/js/email-editor/src/middleware/strip-post-status-on-save.ts (1 hunks)
  • packages/js/email-editor/src/store/initial-state.ts (1 hunks)
  • packages/js/email-editor/src/store/selectors.ts (2 hunks)
  • packages/js/email-editor/src/store/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/js/email-editor/src/editor.tsx
  • packages/js/email-editor/src/global.d.ts
  • packages/js/email-editor/src/store/selectors.ts
  • packages/js/email-editor/src/store/types.ts
  • packages/js/email-editor/src/store/initial-state.ts
  • packages/js/email-editor/src/hacks/publish-save.tsx
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)

**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable

Files:

  • packages/js/email-editor/src/middleware/strip-post-status-on-save.ts
**/*.{php,js,ts,jsx,tsx}

⚙️ CodeRabbit Configuration File

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

Files:

  • packages/js/email-editor/src/middleware/strip-post-status-on-save.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: NeosinneR
PR: woocommerce/woocommerce#0
File: :0-0
Timestamp: 2025-06-26T14:25:08.421Z
Learning: In WooCommerce transactional emails, product images have historically had display issues due to lazy loading attributes being applied, which email clients cannot process since they don't execute JavaScript. This issue existed in both old and new email templates, but became more visible with the new email template system. The fix involves preventing lazy loading on attachment images specifically during email generation by adding skip classes and data attributes.
Learnt from: triple0t
PR: woocommerce/woocommerce#59186
File: packages/js/email-editor/src/store/initial-state.ts:9-10
Timestamp: 2025-06-26T12:13:32.062Z
Learning: In WooCommerce email editor store initialization (packages/js/email-editor/src/store/initial-state.ts), the current_post_id and current_post_type from window.WooCommerceEmailEditor are required parameters that should cause explicit errors if missing, rather than using fallback values or optional chaining. The design preference is to fail fast when critical initialization data is unavailable.
Learnt from: jorgeatorres
PR: woocommerce/woocommerce#59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in `plugins/woocommerce/changelog/` directory and are processed during releases, not at the repository root level.
Learnt from: ralucaStan
PR: woocommerce/woocommerce#58782
File: plugins/woocommerce/client/blocks/assets/js/base/utils/render-frontend.tsx:0-0
Timestamp: 2025-06-16T16:12:12.148Z
Learning: For WooCommerce checkout blocks, lazy loading was removed in favor of direct imports to prevent sequential "popping" effects during component loading. This approach prioritizes user experience over code splitting, with minimal bundle size impact and improved performance (1.7s to 1.1s speed score improvement). The checkout flow benefits from having all components load together rather than incrementally.
Learnt from: lysyjan
PR: woocommerce/woocommerce#59931
File: packages/js/email-editor/src/hacks/publish-save.tsx:0-0
Timestamp: 2025-07-23T14:53:29.447Z
Learning: In WooCommerce email editor (packages/js/email-editor/src/hacks/publish-save.tsx), the currentPost obtained from select(editorStore).getCurrentPost() is guaranteed to always be a post object, so null safety checks are not required when accessing its properties like status.
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59900
File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/attribute-filter/inspector.tsx:0-0
Timestamp: 2025-07-24T05:37:00.907Z
Learning: The DisplayStyleSwitcher component in plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/components/display-style-switcher/index.tsx has been updated so that its onChange prop accepts only a string type (not string | number | undefined), eliminating the need for type assertions when using this component.
📚 Learning: in woocommerce email editor (packages/js/email-editor/src/hacks/publish-save.tsx), the currentpost o...
Learnt from: lysyjan
PR: woocommerce/woocommerce#59931
File: packages/js/email-editor/src/hacks/publish-save.tsx:0-0
Timestamp: 2025-07-23T14:53:29.447Z
Learning: In WooCommerce email editor (packages/js/email-editor/src/hacks/publish-save.tsx), the currentPost obtained from select(editorStore).getCurrentPost() is guaranteed to always be a post object, so null safety checks are not required when accessing its properties like status.

Applied to files:

  • packages/js/email-editor/src/middleware/strip-post-status-on-save.ts
  • packages/js/email-editor/changelog/add-middleware-to-strip-post-status-on-save
📚 Learning: in woocommerce email editor store initialization (packages/js/email-editor/src/store/initial-state.t...
Learnt from: triple0t
PR: woocommerce/woocommerce#59186
File: packages/js/email-editor/src/store/initial-state.ts:9-10
Timestamp: 2025-06-26T12:13:32.062Z
Learning: In WooCommerce email editor store initialization (packages/js/email-editor/src/store/initial-state.ts), the current_post_id and current_post_type from window.WooCommerceEmailEditor are required parameters that should cause explicit errors if missing, rather than using fallback values or optional chaining. The design preference is to fail fast when critical initialization data is unavailable.

Applied to files:

  • packages/js/email-editor/src/middleware/strip-post-status-on-save.ts
🔇 Additional comments (3)
packages/js/email-editor/src/middleware/strip-post-status-on-save.ts (2)

115-127: Validate concurrent save handling in strip-post-status middleware

We ran an AST search and found dozens of saveEntityRecord calls across the repo, meaning multiple save flows can be in flight simultaneously. Since this middleware dispatches an optimistic status update before actually calling the API, concurrent saves for the same post could overwrite each other’s status.

Please verify:

  • Whether concurrent save flows for a single post are possible in your application.
  • If the current optimistic update is acceptable, or if you should add a queuing/locking mechanism or at least inline documentation to call out the potential race.

Location to review:

  • packages/js/email-editor/src/middleware/strip-post-status-on-save.ts (lines 115–127)

89-97: Add validation for additional recordOrId properties

While you validate that recordOrId.id is a number, the function should also handle cases where recordOrId might be just an ID number (not an object), which is a valid input for saveEntityRecord.

-// Ensure recordOrId is object with numeric id
-if (
-	typeof recordOrId !== 'object' ||
-	recordOrId === null ||
-	typeof recordOrId.id !== 'number'
-) {
-	return await originalActions[ storeName ][
-		actionName
-	]( ...args );
-}
+// Handle both object and number forms of recordOrId
+if ( typeof recordOrId === 'number' ) {
+	// If it's just an ID, we can't strip status anyway
+	return await originalActions[ storeName ][
+		actionName
+	]( ...args );
+}
+
+// Ensure recordOrId is object with numeric id
+if (
+	typeof recordOrId !== 'object' ||
+	recordOrId === null ||
+	typeof recordOrId.id !== 'number'
+) {
+	return await originalActions[ storeName ][
+		actionName
+	]( ...args );
+}

Likely an incorrect or invalid review comment.

packages/js/email-editor/changelog/add-middleware-to-strip-post-status-on-save (1)

1-4: LGTM!

The changelog entry follows the correct format and clearly describes the middleware addition.

@lysyjan lysyjan requested a review from triple0t August 6, 2025 10:46
@lysyjan lysyjan assigned triple0t and unassigned lysyjan Aug 6, 2025
Copy link
Contributor

github-actions bot commented Aug 6, 2025

Testing Guidelines

Hi @triple0t ,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

Copy link
Contributor

@triple0t triple0t left a comment

Choose a reason for hiding this comment

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

Hi @lysyjan, Thanks for the PR.

I'm trying to understand this PR a little more.

Can you explain why we are stripping the post status on the editor core and not in the integrations themselves (e.g, MailPoet)?

What side effect would this change have?
Is there an alternative considered?

@triple0t triple0t assigned lysyjan and unassigned triple0t Aug 7, 2025
@lysyjan
Copy link
Contributor Author

lysyjan commented Aug 8, 2025

Can you explain why we are stripping the post status on the editor core and not in the integrations themselves (e.g, MailPoet)?

That's a good point. I was so focused on the problem that I didn't consider this option, but it looks like the best solution.

@triple0t I am going to move the middleware into MailPoet. Do you agree with this approach? This step should reduce the size of this PR to two tiny fixes. We can add this layer later when other integrators need similar behavior.

@triple0t
Copy link
Contributor

triple0t commented Aug 8, 2025

I am going to move the middleware into MailPoet. Do you agree with this approach? This step should reduce the size of this PR to two tiny fixes. We can add this layer later when other integrators need similar behavior.

@lysyjan, yes, I'm okay with that.

@lysyjan
Copy link
Contributor Author

lysyjan commented Aug 8, 2025

@triple0t I moved the mindleware into MailPoet plugin, so this PR contains only tiny fixes and adding the export storeName that is used in MailPoet.

@lysyjan lysyjan removed their assignment Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ballade Issues related to block-based email editor package: @woocommerce/email-editor issues related to the @woocommerce/email-editor package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants