Skip to content

Social: render connection template in per-network preview#48603

Merged
manzoorwanijk merged 4 commits intotrunkfrom
fix/social/per-network-connection-template
May 7, 2026
Merged

Social: render connection template in per-network preview#48603
manzoorwanijk merged 4 commits intotrunkfrom
fix/social/per-network-connection-template

Conversation

@manzoorwanijk
Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk commented May 7, 2026

Follow-up to #48568 (SOCIAL-453).

Proposed changes

#48568 prefilled the per-network editor's message field with connection.template when no per-post override was set, but only in the form input. This PR aligns the rest of the pipeline with that behavior:

  • useRenderMessageItems: in per-network mode, fall back to connection.template (then globalMessage) when connection.message is empty, so the items POSTed to wpcom/v2/publicize/render-messages match what the form displays. Global mode is unchanged (connection.message ?? globalMessage).
  • useConnectionPreviewData: apply the same fallback to baseMessage so the non-rendered fallback (templates-disabled sites, or while the rendered batch is loading) also shows the connection template.
  • usePerNetworkCustomization.syncConnections: when toggling per-network mode on, do not overwrite connection.message for connections that have their own template — leaving it undefined lets the editor and preview fall back to the connection template instead of clobbering it with the global share message.

Does this pull request change what data or activity we track or use?

No.

Testing instructions

Prerequisites: site features include social-enhanced-publishing and social-message-templates, plus a Jetpack Social paid plan (so per-network customization is available).

  1. Connection template flows through to the per-network preview

    • Set a connection template (e.g. Hi from {network}: {post_title}) for one connection in connection management.
    • Open the block editor for a post and open the customize-and-preview UI.
    • Enable per-network customization.
    • Open that connection's tab. The Message field should be prefilled with the connection template, and the preview pane should render that template (not the global share message).
  2. Toggling per-network mode preserves the connection template

    • Set a non-empty global share message in the post's main share field.
    • Toggle per-network mode off, then on again.
    • For the connection that has its own template, the Message field should still be empty (so the connection-template prefill is shown), not the global share message.
  3. Switching back to global mode does not bleed the connection template

    • After step 2, toggle per-network mode off (back to global mode).
    • The preview should render the global share message — not the connection template.
  4. No regression for connections without a template

    • For a connection that does not have its own template, the per-network editor and preview should still fall back to the global share message (or default network template), as before.
  5. Automated checks

    • pnpm --filter @automattic/jetpack-publicize typecheck
    • pnpm --filter @automattic/jetpack-publicize test
Before After

manzoorwanijk and others added 4 commits May 7, 2026 16:37
In per-network mode, the form prefills the message field with
`connection.template` when no per-post override is set, but the
preview pipeline still resolved messages via `connection.message ?? globalMessage`,
so the rendered preview ignored the connection template.

Mirror the form's fallback chain in `useRenderMessageItems` (the
items POSTed to `wpcom/v2/publicize/render-messages`) and in the
`baseMessage` of `useConnectionPreviewData` (the non-rendered
fallback shown while the rendered batch is loading or when
templates are disabled). Also remove a leftover `console.log`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`syncConnections` runs when per-network mode is enabled and
copies the global share message + media into each connection
that has no existing customization. For connections that have
their own `template` set, that copy was overwriting the template
with the global message (or with `''`), preventing the
connection-template fallback from ever taking effect in
per-network mode.

Skip writing `message` for connections that have a `template`,
so `connection.message` stays undefined and the form / preview
fall back to the connection template. Media fields still sync
as before since per-network mode forces attachment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The earlier render-pipeline fix applied the `connection.template`
fallback unconditionally, so in global mode the preview started
rendering the connection template instead of the global share
message. Gate the template fallback on `isPerNetworkMode` so
global mode falls through to `globalMessage` as it did before.

`connection.message` priority is preserved in both modes,
matching the existing tests and `useConnectionPreviewData`'s
rendered-batch behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@manzoorwanijk manzoorwanijk self-assigned this May 7, 2026
@manzoorwanijk manzoorwanijk requested a review from gmjuhasz May 7, 2026 11:18
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/social/per-network-connection-template branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/social/per-network-connection-template

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Feature] Publicize Now Jetpack Social, auto-sharing [Package] Publicize labels May 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 7, 2026
Copy link
Copy Markdown
Contributor

@gmjuhasz gmjuhasz left a comment

Choose a reason for hiding this comment

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

Code seems straight forward and I cant reproduce the bleed with the changes

@manzoorwanijk manzoorwanijk added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels May 7, 2026
@manzoorwanijk manzoorwanijk merged commit 8d92d39 into trunk May 7, 2026
78 of 79 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/social/per-network-connection-template branch May 7, 2026 11:33
@jp-launch-control
Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/packages/publicize/_inc/hooks/use-per-network-customization/index.ts 22/29 (75.86%) -8.75% 3 ❤️‍🩹
projects/packages/publicize/_inc/hooks/use-connection-preview-data/index.ts 31/40 (77.50%) -1.29% 2 ❤️‍🩹
projects/packages/publicize/_inc/hooks/use-render-message-items/index.ts 43/54 (79.63%) 2.08% 0 💚

Full summary · PHP report · JS report

@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Ready to Merge Go ahead, you can push that green button! labels May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Publicize Now Jetpack Social, auto-sharing [Package] Publicize [Status] UI Changes Add this to PRs that change the UI so documentation can be updated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants