Skip to content

Fix embedded preview styles leaking into the note tree#9633

Open
AllanZyne wants to merge 2 commits intoTriliumNext:mainfrom
AllanZyne:yang/fix/grid_view
Open

Fix embedded preview styles leaking into the note tree#9633
AllanZyne wants to merge 2 commits intoTriliumNext:mainfrom
AllanZyne:yang/fix/grid_view

Conversation

@AllanZyne
Copy link
Copy Markdown

@AllanZyne AllanZyne commented May 2, 2026

Summary

  • Remove embedded <style> tags when rendering trimmed note previews.
  • Prevent imported note CSS from leaking out of Grid/List preview cards and changing unrelated UI such as FancyTree spacing.
  • Add a regression test covering trimmed previews with embedded global li styles.

Root Cause

Grid view renders child note previews with trim: true. Some imported notes can contain embedded <style> tags, for example li { margin-bottom: 8pt; }. Because those preview nodes are inserted into the main document, the embedded CSS applies globally and changes the left-pane FancyTree item spacing.

Test Plan

  • npx vitest run apps/client/src/services/content_renderer_text.spec.ts --config apps/client/vite.config.mts
  • Manually verified against a local Trilium instance that opening a Grid view note no longer changes #left-pane li margin-bottom from 0px.

Notes

This only strips embedded styles from trimmed previews. Full note rendering is left unchanged.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 2, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces logic to strip embedded <style> tags from rendered content when the trim option is enabled, preventing unintended styling in preview modes. A new test case was added to verify this behavior. The reviewer suggested moving this logic into the postProcessRichContent function to ensure it applies to all rich content types, such as Markdown notes, and to simplify the implementation using jQuery's .remove() method.

if (blob && !isHtmlEmpty(blob.content)) {
$renderedContent.append($('<div class="ck-content">').html(blob.content));
await postProcessRichContent(note, $renderedContent, options);
removeEmbeddedStylesFromTrimmedPreview($renderedContent[0], options);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The logic to remove embedded styles is currently only applied to text notes. However, Markdown notes (which also use postProcessRichContent in content_renderer.ts) likely suffer from the same issue when rendered in grid views.

Consider moving this logic into postProcessRichContent so it's automatically applied to all rich content types when options.trim is enabled. If moved there, you can use the more concise $renderedContent.find('style').remove(); to achieve the same result.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Implemented in follow-up commit ac1e890. The style stripping now runs inside postProcessRichContent for trimmed rich-content previews, and the test coverage includes both imported text previews and markdown previews.

@AllanZyne AllanZyne changed the title Fix grid view issue Fix embedded preview styles leaking into the note tree May 2, 2026
@AllanZyne
Copy link
Copy Markdown
Author

Hi @adoriandoran @eliandoran, can you please review this PR? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant