Skip to content

Conversation

fueko
Copy link
Contributor

@fueko fueko commented Aug 21, 2025

When using the {{ghost_head}} helper with the exclude option (for example excluding {{ghost_head exclude="comment_counts"}}), the accent color style can disappear in the Admin Preview.

The issue occurs because the accent style is currently appended to the last style or script element in the head output. In the Admin Preview environment, script tags are sanitized or removed, and if the accent style was attached to one of them, it gets lost. This leads to the accent color not appearing in Admin, while still working correctly on the frontend. The inconsistency is confusing for theme developers and customers testing themes inside Admin.

Fix:

The injection logic has been adjusted so that the accent color is only appended to the last style element in the head output. If no style element exists, it will be added as a separate entry. This ensures that the accent color is never tied to a script element that could be removed in Admin Preview.

Copy link
Contributor

coderabbitai bot commented Aug 21, 2025

Walkthrough

In ghost/core/core/frontend/helpers/ghost_head.js, the logic for placing the accent color style tag was adjusted. The search for an insertion point now targets only the last closing </style> tag using /</style>/, replacing the previous check for either </style> or </script> via /</(style|script)>/. The variable was renamed from existingScriptIndex to existingStyleIndex. If a closing </style> is found (existingStyleIndex !== -1), the style is appended to it; otherwise, a new <style>:root {--ghost-accent-color: ...}</style> tag is added.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

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

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
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 (2)
ghost/core/core/frontend/helpers/ghost_head.js (2)

340-343: Make the matcher resilient (case-insensitive, optional whitespace) and stringify nodes.

Some entries in head are SafeString objects and user/3rd-party injections may close </STYLE> with different casing or whitespace. Minor hardening below:

Apply this diff:

-            const existingStyleIndex = _.findLastIndex(head, str => /<\/style>/.test(str));
+            // Be robust to SafeString objects, casing, and stray whitespace before '>'
+            const existingStyleIndex = _.findLastIndex(
+                head,
+                (node) => /<\/style\s*>/i.test(String(node))
+            );

342-343: Add a newline when concatenating for readability (nit).

Purely cosmetic; keeps the generated markup readable when multiple styles are concatenated into a single array entry.

-                head[existingStyleIndex] = head[existingStyleIndex] + styleTag;
+                head[existingStyleIndex] = `${head[existingStyleIndex]}\n    ${styleTag}`;
📜 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 02e176b and abe5337.

📒 Files selected for processing (1)
  • ghost/core/core/frontend/helpers/ghost_head.js (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: kevinansfield
PR: TryGhost/Ghost#23824
File: ghost/core/core/server/services/email-service/email-templates/partials/styles.hbs:919-926
Timestamp: 2025-06-13T11:57:58.226Z
Learning: In `ghost/core/core/server/services/email-service/email-templates/partials/styles.hbs`, some style blocks (e.g., `.latest-post p` and `.latest-post p a`) still use the legacy colour `#73818c` on purpose; they are later overridden by `emailCustomization` feature rules, as noted by inline TODO comments. These occurrences should not be flagged as inconsistencies.
📚 Learning: 2025-06-13T11:57:58.226Z
Learnt from: kevinansfield
PR: TryGhost/Ghost#23824
File: ghost/core/core/server/services/email-service/email-templates/partials/styles.hbs:919-926
Timestamp: 2025-06-13T11:57:58.226Z
Learning: In `ghost/core/core/server/services/email-service/email-templates/partials/styles.hbs`, some style blocks (e.g., `.latest-post p` and `.latest-post p a`) still use the legacy colour `#73818c` on purpose; they are later overridden by `emailCustomization` feature rules, as noted by inline TODO comments. These occurrences should not be flagged as inconsistencies.

Applied to files:

  • ghost/core/core/frontend/helpers/ghost_head.js
⏰ 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). (8)
  • GitHub Check: Ghost-CLI tests
  • GitHub Check: E2E tests
  • GitHub Check: Acceptance tests (Node 22.13.1, sqlite3)
  • GitHub Check: Acceptance tests (Node 22.13.1, mysql8)
  • GitHub Check: Legacy tests (Node 22.13.1, sqlite3)
  • GitHub Check: Unit tests (Node 22.13.1)
  • GitHub Check: Legacy tests (Node 22.13.1, mysql8)
  • GitHub Check: Lint
🔇 Additional comments (1)
ghost/core/core/frontend/helpers/ghost_head.js (1)

340-343: Good fix: limiting the insertion point to only the last </style> avoids Admin Preview losses.

Targeting only style blocks decouples the accent style from script sanitization/removal in Admin Preview and matches the intent described in the PR. Nice, minimal surface-area change.

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.

1 participant