Skip to content

fix(server): re-expose omitLineBreaks render option#767

Merged
harlan-zw merged 3 commits into
mainfrom
feat/render-omit-line-breaks
Jun 5, 2026
Merged

fix(server): re-expose omitLineBreaks render option#767
harlan-zw merged 3 commits into
mainfrom
feat/render-omit-line-breaks

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

Resolves #766

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

renderSSRHead(head, { omitLineBreaks }) is deprecated in favour of head.render(), but head.render() took no arguments and createHead only forwarded tagWeight to the renderer, so omitLineBreaks could not be applied. The only non-deprecated path was post-processing with replaceAll('\n', ''), which also strips newlines inside inline <script>/<style>/JSON-LD content.

This forwards the render options into the renderer so head.render() honours them:

  • createHead({ omitLineBreaks }) (deprecated, JSDoc points to MinifyPlugin) wires the option through createServerRenderer into ssrRenderTags.
  • The ssr:render hook ctx now exposes a per-render options object, so plugins can flip render behaviour before the join happens.
  • MinifyPlugin({ omitLineBreaks }) uses that hook to drop separators surgically. Because it sets the renderer flag rather than stripping the string, skip-types (importmap, speculationrules), sub-20-char scripts, and js: false content keep their internal newlines.

Tests cover the createHead path and the MinifyPlugin path including the previously fragile skip cases. MinifyPlugin minifies the inline content where the real bytes are; omitLineBreaks only removes separators, so they compose rather than replace each other.

Summary by CodeRabbit

  • New Features

    • Added an omitLineBreaks option to produce more compact head output by removing separators between tags while preserving newlines inside inline scripts, styles, and JSON-LD.
  • Breaking Changes

    • The SSR render hook now receives per-render options alongside tags; hook payload shape changed and can affect rendered output.
  • Documentation

    • Updated SSR-render hook and minify plugin docs with new option and guidance.
  • Tests

    • Added tests covering omitLineBreaks behavior.

…inifyPlugin

Forward render options into the renderer so head.render() can honour
omitLineBreaks without the deprecated renderSSRHead. The ssr:render hook
now exposes a per-render options object, letting plugins flip render
behaviour surgically (separators only) instead of a blanket string strip.

Resolves #766
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR exposes omitLineBreaks as a render option on createHead/createServerHead, extends the ssr:render hook to receive a mutable per-render options context, and updates the Minify plugin, tests, and docs to use and document this option.

Changes

SSR Render Option Exposure

Layer / File(s) Summary
Hook signature and SSR context enhancement
packages/unhead/src/types/hooks.ts, packages/unhead/src/server/renderSSRHead.ts
The ssr:render hook now receives ctx: { tags, options }. createServerRenderer builds a per-render ctx with cloned options, passes it to hooks, and renders using the (possibly mutated) ctx.options.
Public API and plugin option contracts
packages/unhead/src/types/head.ts, packages/unhead/src/plugins/minify.ts
CreateServerHeadOptions gains a deprecated omitLineBreaks?: boolean. MinifyPluginOptions adds omitLineBreaks?: boolean.
Plugin and server integration
packages/unhead/src/plugins/minify.ts, packages/unhead/src/server/createHead.ts
The Minify plugin sets ctx.options.omitLineBreaks = true when configured. createHead forwards omitLineBreaks into the SSR renderer factory.
Feature validation tests
packages/unhead/test/unit/plugins/minify.test.ts, packages/unhead/test/unit/server/ssr.test.ts
New tests assert omitLineBreaks: true omits inter-tag separators while preserving internal newlines for excluded or under-threshold inline content.
Docs: ssr:render hook update & plugin guide
docs/head/7.api/hooks/13.ssr-render.md, docs/head/1.guides/plugins/minify.md
Documentation updated to include ctx.options in the ssr:render hook signature and to document MinifyPlugin({ omitLineBreaks: true }) and its effects.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit hops through render trees,
Tweaks options with a gentle breeze,
Hooks now carry mutable light,
Tags line up without their bite,
Hooray—no postfix fixes, please. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: re-exposing the omitLineBreaks render option through createHead and head.render() to replace the deprecated renderSSRHead function.
Description check ✅ Passed The description follows the template structure with linked issue, type of change, and detailed explanation of the implementation approach and rationale.
Linked Issues check ✅ Passed The PR fully addresses issue #766 by implementing all proposed requirements: forwarding omitLineBreaks through createHead, exposing per-render options in the ssr:render hook, and implementing MinifyPlugin integration with comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are within scope of issue #766, covering the minify plugin option, server-side head creation, SSR rendering, type definitions, hooks, documentation, and tests—all directly related to exposing render options.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/render-omit-line-breaks

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Bundle Size Gzipped
Client (Minimal) 10.8 kB 4.4 kB
Server (Minimal) 10.7 kB → 10.7 kB 🔴 +0.1 kB 4.3 kB
Vue Client (Minimal) 11.8 kB 4.9 kB
Vue Server (Minimal) 11.6 kB → 11.7 kB 🔴 +0.1 kB 4.8 kB

@harlan-zw harlan-zw changed the title feat(unhead): expose omitLineBreaks render option on createHead fix(unhead): expose omitLineBreaks render option on createHead Jun 5, 2026
@harlan-zw harlan-zw changed the title fix(unhead): expose omitLineBreaks render option on createHead fix(ssr): expose omitLineBreaks render option on createHead Jun 5, 2026
@harlan-zw harlan-zw changed the title fix(ssr): expose omitLineBreaks render option on createHead fix(server): re-expose omitLineBreaks render option Jun 5, 2026
@harlan-zw harlan-zw changed the title fix(server): re-expose omitLineBreaks render option fix(server): re-expose omitLineBreaks render option Jun 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/head/1.guides/plugins/minify.md`:
- Around line 55-76: The markdown code block in the "Omit Line Breaks" section
is missing required blank lines around the fenced code fence for proper markdown
formatting. Add a blank line immediately after the opening ::code-block line and
before the closing :: line, so that the ```ts [Input]``` code fence has proper
spacing on both sides according to markdown best practices.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16d29d65-1a15-4052-a8c5-6e686849b3e2

📥 Commits

Reviewing files that changed from the base of the PR and between 78562ad and 87e36ba.

📒 Files selected for processing (2)
  • docs/head/1.guides/plugins/minify.md
  • docs/head/7.api/hooks/13.ssr-render.md

Comment on lines +55 to +76
/**
* Omit the line breaks between rendered tags, producing a single line of output.
* Only removes the separators between tags; newlines inside inline content are
* left to the minifiers above.
* @default false
*/
omitLineBreaks?: boolean
}
```
::

### Omit Line Breaks

By default tags render one per line. Set `omitLineBreaks` to render them on a single line. This only drops the separators between tags, so newlines inside inline `<script>`/`<style>`/JSON-LD content are preserved (the minifiers handle those):

::code-block
```ts [Input]
MinifyPlugin({
omitLineBreaks: true,
})
```
::

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add blank lines around fenced code blocks.

Markdown best practices require blank lines before and after code fences for consistent rendering.

📝 Proposed formatting fixes
 }
+

::

Omit Line Breaks

By default tags render one per line. Set omitLineBreaks to render them on a single line. This only drops the separators between tags, so newlines inside inline <script>/<style>/JSON-LD content are preserved (the minifiers handle those):

::code-block
+

MinifyPlugin({
  omitLineBreaks: true,
})

::

</details>

<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion
  /**
   * Omit the line breaks between rendered tags, producing a single line of output.
   * Only removes the separators between tags; newlines inside inline content are
   * left to the minifiers above.
   * `@default` false
   */
  omitLineBreaks?: boolean
}

🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 63-63: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


[warning] 71-71: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


[warning] 75-75: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/head/1.guides/plugins/minify.md` around lines 55 - 76, The markdown code
block in the "Omit Line Breaks" section is missing required blank lines around
the fenced code fence for proper markdown formatting. Add a blank line
immediately after the opening ::code-block line and before the closing :: line,
so that the ```ts [Input]``` code fence has proper spacing on both sides
according to markdown best practices.

@harlan-zw harlan-zw merged commit 9560425 into main Jun 5, 2026
8 checks passed
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.

Expose renderSSRHead render options (e.g. omitLineBreaks) on createHead so head.render() can replace it

1 participant