question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Global style injection in plugins doesn't work for twind/shim

See original GitHub issue

Reproduction

I was expecting “test button1” button to have same paddings as “test button2” button which is takes its styles from btn class.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
danielweckcommented, Apr 2, 2021

This works (and important is not needed thanks to using preflight with a plain button selector instead of the :global css() which I gave as an example (where the :root “prefix” in the selector increased its specificity):

<!DOCTYPE html>
<html lang="en" hidden>
  <head>
    <script type="module">
      import {setup} from "https://cdn.skypack.dev/twind/shim"
      import {tw, apply} from "https://cdn.skypack.dev/twind"
      import {css} from "https://cdn.skypack.dev/twind/css"

      setup({
      preflight: {
      	'button': apply('px-4 py-2 block bg-red-600 text-green-400')
      },
        plugins: {
          btn: 'bg-black text-white'
        }
      })
      

/*
      tw(css({
         ':global': {
           ':root button': apply`px-4 py-2 block bg-red-600 text-green-400`
         }
      }))
      */
    </script>
  </head>
  <body>
    <button class="btn">test button2</button>
    <button>test button1</button>
  </body>
</html>
0reactions
sastancommented, Jan 25, 2022

apply is fixed in twind v1.

Please give it a try. Here are some links to get you started:

Closing this for now. Feel free to re-open.

Read more comments on GitHub >

github_iconTop Results From Across the Web

#56644 (Global styles don't work for most blocks (paragraphs ...
Go to the site editor. Open the global styles sidebar. Open the blocks section. Navigate to the paragraph block (or button, heading, etc,...
Read more >
Moving global style sheets above styled-components in <head>
In Gatsby plugins, this type of injection happens in onRenderBody . I played around with it and was able to programatically inject the...
Read more >
Dependency Injection in Drupal 8 Plugins - Chromatic
In the aforementioned D8 Cache API blog post, I was building a block Plugin and grabbing the current user's ID with the global...
Read more >
gatsby-plugin-global-styles
A Gatsby plugin for creating independent global CSS styles, and automatically placing them at the top of the <head> element. The plugin does...
Read more >
Global Styles - Emotion
Sometimes you might want to insert global css like resets or font faces. You can use the Global component to do this. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found