Skip to content

Commit

Permalink
Keep Trix dynamic styles in the head
Browse files Browse the repository at this point in the history
Trix dynamically adds some styles to the head that we need to keep around.
Otherwise, the editor will not render correctly after a page change.

We can detect those styles because Trix also adds a `data-tag-name`
attribute to the style elements it adds.

Ideally, we would move those styles to Trix's CSS file, but for now we'll
just skip removing them. We don't want to force everyone upgrading to
Turbo v8 to also upgrade Trix.

Ref:

- https://github.com/basecamp/trix/blob/06d8b1db5fb682d007c5ca041884f6297674c8b7/src/trix/elements/trix_editor_element.js#L108-L162
- https://github.com/basecamp/trix/blob/06d8b1db5fb682d007c5ca041884f6297674c8b7/src/trix/core/helpers/custom_elements.js#L11
  • Loading branch information
afcapel committed Jan 18, 2024
1 parent a73f6f1 commit 8fbb573
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/drive/page_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ export class PageRenderer extends Renderer {

removeUnusedHeadStylesheetElements() {
for (const element of this.unusedHeadStylesheetElements) {
document.head.removeChild(element)
// Trix dynamically adds styles to the head that we want to keep around
// Long term we should moves those styles to Trix's CSS file
// but for now we'll just skip removing them
if (!element.dataset.tagName) {
document.head.removeChild(element)
}
}
}

Expand Down

0 comments on commit 8fbb573

Please sign in to comment.