Skip to content

Fix Text Animation destroying links added inside animated text - #285

Merged
davidperezgar merged 4 commits into
trunkfrom
fix-text-animation-strips-links
Sep 4, 2026
Merged

Fix Text Animation destroying links added inside animated text#285
davidperezgar merged 4 commits into
trunkfrom
fix-text-animation-strips-links

Conversation

@Castellon-ACM

@Castellon-ACM Castellon-ACM commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a real bug reported by a user: adding a link to part of the text inside a block "breaks" — the link silently disappears.

Root cause

Every character-splitting animation handler in assets/text-animation/animations/*.js (fade-in, wave, typewriter, etc. — applicable to any paragraph/heading with the FrontBlocks "Text Animation" panel enabled, or the dedicated Text Animation block) rebuilds its element from el.textContent on first play, discarding all inline HTML. If the author had wrapped part of the text in a link, the <a> itself was destroyed — only its unlinked text survived.

Verified this was unrelated to PR #274 (that PR isn't even merged, and only touches server-side attribute registration for the entrance-animation feature — no RichText/link code at all).

Fix

assets/text-animation/frontblocks-text-animation-frontend.js's init() now skips the destructive per-character rebuild entirely for any animated element whose direct children include an inline-formatting tag (a, strong, b, em, i, mark, code, abbr, sub, sup, span, kbd). That content is left exactly as authored — link intact and clickable — at the cost of that specific text not playing the character animation. A missing animation is a far safer failure than silently destroying the author's link.

Test plan

  • New regression test (tests/js/text-animation-inline-formatting.test.js, npm run test:text-animation) covering: content with no formatting is still animated; content with a link, or any other inline tag, is skipped.
  • Wired into CI alongside the existing test:cookie-notice job.
  • Live-verified in a real browser (Playwright against a local WP install): created a paragraph, enabled the "Text Animation" panel (fade-in), selected a word, added a link via the toolbar, published, and confirmed on the actual frontend that the <a href="..."> survives, has cursor: pointer, and a real click navigates to the target URL.
  • Full PHPUnit suite unaffected (no PHP touched): 389 tests, 769 assertions.
  • composer lint (phpcs) clean.
Open WordPress Playground Preview

Every character-splitting animation handler rebuilt its element from
el.textContent, which silently discards any inline HTML — most
importantly, a link the author added to part of the text: the <a>
itself was destroyed on the very first animation play, leaving only
its unlinked text.

Skip the destructive per-character rebuild entirely for any animated
element whose content contains inline formatting (a, strong, b, em,
i, mark, code, abbr, sub, sup, span, kbd). The text is left exactly
as authored — link intact and clickable — at the cost of that
specific text not playing the character animation, which is a much
safer failure than silently destroying the author's link.
Verifies init() skips the character-splitting handler for any
element whose direct children include a link or other inline
formatting tag, and hands unformatted content through unchanged.
Registers test:text-animation in package.json and adds it to the
JavaScript tests CI job alongside the existing cookie-notice test.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@davidperezgar

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@davidperezgar
davidperezgar merged commit 55525f7 into trunk Sep 4, 2026
6 checks passed
@davidperezgar
davidperezgar deleted the fix-text-animation-strips-links branch September 4, 2026 11:03
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.

2 participants