Skip to content

Remove jQuery from user notes preview - #529

Open
cbravobernal wants to merge 6 commits into
WordPress:trunkfrom
cbravobernal:refactor/jquery-from-user-notes-preview
Open

cbravobernal wants to merge 6 commits into
WordPress:trunkfrom
cbravobernal:refactor/jquery-from-user-notes-preview

Conversation

@cbravobernal

@cbravobernal cbravobernal commented Jul 22, 2024 •

Copy link
Copy Markdown
Contributor

What

Remove jQuery from user-notes-preview.js

Why

jQuery is known to inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality.

@cbravobernal
cbravobernal marked this pull request as ready for review July 23, 2024 08:46
@cbravobernal cbravobernal changed the title Draft: Remove jQuery from user notes preview Remove jQuery from user notes preview Jul 23, 2024
} );
// Make first child of the preview focusable.
if ( preview.firstChild ) {
preview.firstChild.setAttribute( 'tabindex', '0' );

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.

I'm getting an error when I test this, it looks like firstChild is a text node, not an html element.

Screenshot 2024-07-25 at 3 52 51 PM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 Looks like a place for firstElementChild

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6762ec8

It's weird I didn't get the error until now 🤔

Comment on lines +17 to +19
spinner = document.createElement( 'span' );
spinner.className = 'spinner';
spinner.style.display = 'none';

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.

This does create the spinner correctly, but apparently it was never styled when we moved to the block theme, so nothing is visible. Not a problem for this PR though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where can I check the old styles?

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.

I wouldn't copy over the old styles, but you could borrow the loading animation from this CSS (it's the loading state for images such as the pattern & style variation screenshots on Themes).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The spinner didn't have any styled, an empty span was appearing. I added the style, but the time of the spinner is quite small.

Screen.Recording.2024-07-29.at.16.46.45.mov

@obenland

Copy link
Copy Markdown
Member

Thanks for this! Two things need fixing before it can go in:

  1. js/user-notes-preview.js — the #commentform .tablist selector runs before the existence guard. The script loads on every singular page, but the comment form only renders for logged-in users on parsed post types, so logged-out visitors and handbook pages get an uncaught TypeError on every load. Move that line inside the if ( textarea && preview && tabs.length > 0 ) block.
  2. src/style/style.scss — the .spinner::after animation references rotate-360, but those keyframes aren't defined in this theme, the parent theme, or any globally loaded mu-plugin CSS. Add a @keyframes rotate-360 { to { transform: rotate(360deg); } } so the spinner actually spins.

Everything else checks out: fetch/nonce handling, escaping, event binding, and the two earlier review threads were addressed.

🤖 Generated with Claude Code

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

Projects

Status: 👀 In review (PRs only)

Development

Successfully merging this pull request may close these issues.

4 participants