Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep Trix dynamic styles in the head #1133

Merged
merged 2 commits into from
Jan 22, 2024
Merged

Keep Trix dynamic styles in the head #1133

merged 2 commits into from
Jan 22, 2024

Conversation

afcapel
Copy link
Collaborator

@afcapel afcapel commented Jan 18, 2024

After #1128 we are dynamically removing styles we're no longer using on page navigations. Unfortunately, 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:

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
Copy link
Collaborator

@kevinmcconnell kevinmcconnell left a comment

Choose a reason for hiding this comment

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

Looks good to me. Shame we have to do it! But it seems like a pragmatic move for now, and the new semantics that we have still make sense 👍

src/core/drive/page_renderer.js Outdated Show resolved Hide resolved
And use it to keep the progress bar styles around, instead of relying
on an id.
@afcapel afcapel merged commit 32b8c30 into main Jan 22, 2024
2 checks passed
@afcapel afcapel deleted the keep-trix-styles branch January 22, 2024 10:04
afcapel added a commit to davidalejandroaguilar/turbo that referenced this pull request Jan 22, 2024
…tclick-behavior

* origin/main:
  Keep Trix dynamic styles in the head (hotwired#1133)
afcapel added a commit that referenced this pull request Jan 25, 2024
To track stylesheets and styles that we can dynamically remove when
navigating.

We introduced this behaviour in #1128
and thought it would be a good default to avoid full page reloads when
styles change.

However, it seems it's quite common for libraries to add stylesheets
and styles to the head that they want to keep around. For example, see

- #1133
- #1139

So let's make this behaviour opt-in by adding a `data-turbo-track="dynamic"`
attribute to stylesheets and styles that we want to dynamically remove when
they are no longer in a new page navigation.

This avoids any breaking changes for existing apps.
afcapel pushed a commit that referenced this pull request Jan 25, 2024
To track stylesheets and styles that we can dynamically remove when
navigating.

We introduced this behaviour in #1128
and thought it would be a good default to avoid full page reloads when
styles change.

However, it seems it's quite common for libraries to add stylesheets
and styles to the head that they want to keep around. For example, see

- #1133
- #1139

So let's make this behaviour opt-in by adding a `data-turbo-track="dynamic"`
attribute to stylesheets and styles that we want to dynamically remove when
they are no longer in a new page navigation.

This avoids any breaking changes for existing apps.
afcapel added a commit to pfeiffer/turbo that referenced this pull request Jan 29, 2024
* origin/main:
  Introduce `turbo:{before-,}morph-{element,attribute}` events
  Turbo 8.0.0-beta.4
  Introduce data-turbo-track="dynamic" (hotwired#1140)
  Ensure that the turbo-frame header is not sent when the turbo-frame has a target of _top (hotwired#1138)
  Turbo 8.0.0-beta.3
  Fix attribute name (hotwired#1134)
  Add InstantClick behavior (hotwired#1101)
  Revert hotwired#926. (hotwired#1126)
  Keep Trix dynamic styles in the head (hotwired#1133)
  Remove unused stylesheets when navigating (hotwired#1128)
  Upgrade idiomorph to 0.3.0 (hotwired#1122)
  Debounce page refreshes triggered via Turbo streams
  Update copyright year to 2024 (hotwired#1118)
  Turbo 8.0.0-beta.2
  Set aria-busy on the form element during a form submission (hotwired#1110)
  Dispatch `turbo:before-fetch-{request,response}` during preloading (hotwired#1034)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants