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

✨ Tailwind v4 #3208

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

✨ Tailwind v4 #3208

wants to merge 15 commits into from

Conversation

retlehs
Copy link
Member

@retlehs retlehs commented Jan 20, 2025

@retlehs retlehs self-assigned this Jan 20, 2025
@retlehs retlehs changed the title 🚧 Tailwind v4 ✨ Tailwind v4 Jan 20, 2025
@retlehs retlehs marked this pull request as ready for review January 20, 2025 21:57
@github-actions github-actions bot added the php Pull requests that update PHP code label Jan 20, 2025
@retlehs retlehs marked this pull request as draft January 20, 2025 22:17
@retlehs retlehs marked this pull request as ready for review January 20, 2025 23:06
@codewithfeeling
Copy link

codewithfeeling commented Jan 21, 2025

This is very promising as a solution to finally getting Sage to work with the API v3 block editor.

The injection works fine folliowing a build with npm build but I can't get it to work in the same way as front styles with hot reloading using npm run dev.

Steps to reproduce:

  1. Add some Tailwind styles in editor.css, for example:
@import "tailwindcss";

.editor-styles-wrapper {
  @apply font-sans bg-blue-50 px-32;
}

.editor-styles-wrapper h1 {
  @apply font-bold text-4xl mb-8;
}

.editor-styles-wrapper p {
  @apply mb-4;
}
  1. Run npm run build - terminal shows the build process output running successfully
  2. Edit a page in wp-admin - styles have been applied as expected:
image
  1. Now run npm run dev - terminal output shows the process is running
  2. Make a change to editor.css, eg. change bg-blue-50 to bg-red-100 and save the file
  3. No changes are observed, even after fully reloading the admin edit page. Expected behaviour is that the changes will apply immediately, as they do on the front side after changing app.css

This means that hot reloading is working on the front but not admin, which is a little confusing.

I can also confirm that installing an API v2 plugin to disable the iframe editor does not fix things. Styles do not hot reload in this scenario.

@retlehs
Copy link
Member Author

retlehs commented Jan 23, 2025

Thank you for testing it out and the feedback! Not yet sure how to tackle the iframe'd editor's CSS in dev mode

@retlehs
Copy link
Member Author

retlehs commented Jan 26, 2025

Pushed some updates this weekend that have improved the integration between Vite's dev server and the iframed block editor a bit for updates made to editor.css, but it still needs some more polish

I left off today with refreshing the page when a change is detected Edit: One more update - 32b3ae4

@retlehs
Copy link
Member Author

retlehs commented Jan 26, 2025

I thought we could get away with this:

/**
 * Add Vite's HMR client to iframed block editor.
 *
 * @return void
 */
add_action('enqueue_block_assets', function () {
    if (! is_admin() || ! get_current_screen()?->is_block_editor()) {
        return;
    }

    if (! Vite::isRunningHot()) {
        return;
    }

    $devUrl = trim(File::get(Vite::hotFile()));
    wp_enqueue_script_module('vite-hmr', $devUrl.'/@vite/client');
});

But it looks like wp_enqueue_script_module isn't currently compatible with the iframed editor (WordPress/gutenberg#64482)

A workaround:

    wp_register_script('vite-hmr', false);
    wp_enqueue_script('vite-hmr');
    wp_add_inline_script('vite-hmr', "
        if (window.self !== window.top) {
            const script = document.createElement('script');
            script.type = 'module';
            script.src = '{$devUrl}/@vite/client';
            document.head.appendChild(script);
        }
    ");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
php Pull requests that update PHP code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants