Giter Site home page Giter Site logo

use-twind-with's People

Contributors

akash-joshi avatar amoutonbrady avatar chopfitzroy avatar eldain avatar itsmapleleaf avatar merodiro avatar rschristian avatar sastan avatar trugamr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

use-twind-with's Issues

Integrated with angular

I have a question.
How to integrated the library with angular ? I still failed to work with angular. except if I use it with remote dependency and I code in html file. thx for reply.

How to wrap the `prerender` function exported from `withTwind`?

I would like to setup hoofd with WMR as described in the docs.

In terms of setting this up with withTwind would it be something like:

const { hydrate, prerender: internal } = withTwind({
   // Options here...
});

export async function prerender(data) {
  const result = await internal(data);
  const head = toStatic();
  const { links = [], metas = [], scripts = [] } = head;

  const elements = new Set([
    ...links.map(props => ({ type: 'link', props })),
    ...metas.map(props => ({ type: 'meta', props })),
    ...scripts.map(props => ({ type: 'script', props }))
  ]);

  return {
    ...result,
    head: {
      lang: head.lang,
      title: head.title,
      elements
    }
  };
};

@twind/preact: tw and css options cannot be enabled without breakage

Reproduction

The CodeSandbox linked in the ReadMe reproduces the error. You'll be met by cannot use 'in' operator to search for "tw" in "This is Twind!"

Explanation

Errors are thrown when searching for the tw and css props on an element with text content, assuming those options are enabled. The text content will have props of whatever the content is, i.e., "This is Twind!". Can't use the in operator to search on a string.

Solution?

I'm not sure why that method is used to begin with ("tw" in props), but solution could be as simple as switching that to props.tw or just checking to ensure props is an object first. I don't have the background knowledge here, so you'll likely know better.

[UNKNOWN_THEME_VALUE] and [UNKNOWN_DIRECTIVE] on Nextjs 12 in extended theme values

Hello,

I'm aware the package was updated to support Nextjs 12, but when I upgrade Next, I get these errors.

image
I have a theme extended in twind.config.ts (some part of the code deleted for legibility) and then used on theme.extend.

image

The only difference between this happening or not is being on Next 11.1.2 or 120.3.
It causes styles to get messed up, adding styles to the wrong places, and some not being used at all. Interestingly, it seems similar to this issue but I'm unsure. tw-in-js/twind#47

If I navigate away from a page then return, then the styles are correct.

dyeXfP7XuB.mp4

WMR: Prerender doesn't always build full page styles

Summary

I'm running into an issue where the full styles for a page are not currently being created in the generated style tag. For example, take this as the root:

export function App() {
  return (
    <LocationProvider>
      <h1 class="text-purple-500">Should be purple</h1>
      <div>
        <Header />
        <ErrorBoundary>
          <Router>
            <Route path="/" component={Home} />
            <Route path="/about" component={About} />
            <Route default component={NotFound} />
          </Router>
        </ErrorBoundary>
      </div>
    </LocationProvider>
  );
}

text-purple-500 will be included in the route /, however, it is not in /about or /error. This is mainly an issue as I'm using Twind without any runtime, so a style not in the style tags results in unstyled content.

Reproduce

  • Clone this repo I've set up: https://github.com/rschristian/twind-prerender-bug

  • Run a production build & then serve the content (yarn build && yarn serve)

  • Navigate to /, notice the top text is purple

  • Navigate to /about, notice the same text is not purple here

[WMR]: Stylesheets not clearing between pages being prerendered

@sastan: do you happen to remember the context of this comment?

// Ensure to start a new async scope
return (data) =>
Promise.resolve().then(async () => {

Running into an issue at the moment where previous styles aren't cleared from the stylesheet, and for whatever reason, this seems to be the culprit.

I've made a reproduction: https://github.com/rschristian/twind-uncleared-sheet-bug

This is just the WMR Example brought up to date and configured to also prerender a 'Not Found' page.

Once you build (npm run build), if you look at the built file (dist/404/index.html) you'll see that Twind has generated a rule for .bg-purple-400, even though it doesn't exist on any content in the page. It does, however, exist in /.

I'm not really sure what you're looking to do with that Promise.resolve().then(...). Replacing that and returning a plain async function seems to fix the issue.

// Ensure to start a new async scope
-return (data) =>
-    Promise.resolve().then(async () => {
+return async (data) => {
        await sheet.reset()
        let { html, ...rest } = await prerender(render(data), options)
        return { ...rest, html: getStyleTag(sheet) + html }
-})
+}
}

SSR of CSS not working > Can not prevent FOUC (NextJS)

Hi there!

I really love what you're doing with Twind. I've been implementing it in our codebase and got really far, but ultimately got blocked on an SSR issue and am unable to move forward.

We're seeing a FOUC on the pages because the CSS isn't getting rendered on server-side, and the styles only come in later on client-side.

In the building stage, we're seeing the LATE_SETUP_CALL notices and have not been able to resolve them. Looked through this open issue, but didn't seem to have a solution.
Screen Shot 2022-04-22 at 3 34 39 PM

In the Twind Next JS Code Sandbox example, the styles are also missing from the head as well. It shows as an empty style tag: <style id="__tw-9"></style> without styles. We're seeing the same thing our end as well. This suggests that React is correctly creating the style element and setting the id: '__' + hash but not inserting any styles within or getting the textContent.

In the Sandbox example, there is a data-next-hide-fouc="true" but we don't want the page empty before the styles come in. We're assuming that SSR should work out of the box with the Twind integration, but is there something we've missed in the documentation that says otherwise? Bit of a loss as to what to do next, so any direction would be greatly appreciated!

Running on:

  • Node.js v15.8.0,
  • twind/next: ^1.0.9,
  • next: ^10.0.0,
  • using the tw function with no shim
  • custom App component + custom twind config
twind.config.js
/** @type {import('twind').Configuration} */
import { setup } from 'twind';
import { withForms } from '@twind/forms';

setup({
    preflight: withForms({
        '@font-face': [
            // fonts here
        ]
    }),
    theme: {
        fontFamily: {
           // fonts here
        },
        colors: {
            // colors here
        }
    }
});

export default {};
pages/_app.js
import React from 'react';
import Head from 'next/head';
import withTwindApp from '@twind/next/app';
import twindConfig from 'twind.config';
import globalAppStyles from './app.global.scss?type=global';

function PastelApp({ Component, pageProps }) {
    return (
        <>
            <Head>
                <meta charSet="utf-8" />
                <meta httpEquiv="X-UA-Compatible" content="IE=edge" />
                <meta
                    name="viewport"
                    content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
                />
            </Head>
            <>
                <style jsx global>
                    {globalAppStyles}
                </style>
            </>
            <Component {...pageProps} />
        </>
    );
}

export default withTwindApp(twindConfig, PastelApp);
pages/_document.tsx
import Document, { Html, Head, Main, NextScript } from 'next/document';
import { tw } from 'twind';
import withTwindDocument from '@twind/next/document';
import twindConfig from '../twind.config';

class MyDocument extends Document {
    static async getInitialProps(context) {
        const initialProps = await Document.getInitialProps(context);
        return { ...initialProps };
    }

    render() {
        return (
            <Html lang="en">
                <Head />
                <body className={tw`pastel-app bg-gray-100`}>
                    <Main />
                    <div className={tw`modal-root`} />
                    <NextScript />
                </body>
            </Html>
        );
    }
}

export default withTwindDocument(twindConfig, MyDocument);
next.config.js
process.env.NODE_ENV = process.env.NODE_ENV || 'development';

const webpack = require('webpack');
const path = require('path');

module.exports = {
    webpack: (config, { _dev, defaultLoaders }) => {
        config.plugins.push(
            new webpack.DefinePlugin({
                'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
            })
        );

        config.module.rules.push({
            test: /\.svg$/,
            use: ['@svgr/webpack']
        });

        config.module.rules.push({
            test: /\.(css|scss)$/,
            use: [
                defaultLoaders.babel,
                {
                    loader: require('styled-jsx/webpack').loader,
                    options: {
                        type: (fileName, options) => options.query.type || 'scoped'
                    }
                },
                {
                    loader: 'sass-loader',
                    options: {
                        sassOptions: {
                            includePaths: [path.resolve(__dirname, './styles')]
                        }
                    }
                }
            ]
        });

        return config;
    }
};

Thanks in advance!

[@twind/preact,wmr] Can't re-render objects by `Cannot set property className of #<Object> which has only a getter`

See https://codesandbox.io/s/rrjq1?file=/public/index.js

In summary, if you use @twind/wmr and import preact/compat, re-render is broken by the error Cannot set property className of #<Object> which has only a getter

Although I haven't investigated why preact/compat causes this issue, the error itself is caused because the component having tw has className getter when re-render.

First time rendering

> s.__lookupGetter__('className')
undefined

Second time rendering

> s.__lookupGetter__('className')
ฦ’ (){return this.class}
preact:formatted:25 Uncaught (in promise) TypeError: Cannot set property className of #<Object> which has only a getter
    at Object.T.i.vnode (preact:formatted:25)

When I manually deleted the getter by debugger, the second time rendering succeeded. So, I guess we can implement that logic in @twind/preact regardless of the issue caused by preact/compat.

LATE_SETUP_CALL error with Next.js

Hi there! Great work with Twind... it's an amazing concept and I am really loving the API.

I tried integrating it with Next.js + Webpack 5 and got this error:

info  - ready on http://localhost:3000
Error: [LATE_SETUP_CALL] {}
    at withTwindDocument (/home/rsc/@dev/@rstacruz/til-2021/node_modules/@twind/next/document/document.cjs:38:27)
    at eval (webpack-internal:///./pages/_document.js:42:123)
    at Object../pages/_document.js (/home/rsc/@dev/@rstacruz/til-2021/.next/server/pages/_document.js:22:1)
    ...

A lot of times it's not really causing any issues (pages continue to work) but sometimes they cause Internal Server Error to show up for some pages.

package.json
  "dependencies": {
    "@twind/next": "^1.0.7",
    "next": "10.1.3",
    "next-mdx-remote": "^2.1.4",
    "twind": "^0.16.13",
  }
twind.config.js
import * as colors from 'twind/colors'
/** @type {import('twind').Configuration} */

export default {
  // mode: 'strict',
  theme: {
    extend: {
      borderColor: {
        line: colors.gray['200'],
      },
      textColor: {
        mute: colors.gray['600'],
        accent: colors.red['600'],
      },
    },
    fontFamily: {
      sans: ['Roboto', 'ui-sans', 'sans-serif'],
      serif: ['Eczar', 'ui-serif', 'Georgia', 'Cambria', 'sans-serif'],
    },
    maxWidth: {
      article: '580px',
    },
  },
}
pages/_document.js
import withTwindDocument from '@twind/next/document'
import twindConfig from '../twind.config'
export default withTwindDocument(twindConfig)
pages/_app.js
import twindConfig from '../twind.config'
import withTwindApp from '@twind/next/app'
import '../styles/globals.css'
import '@fontsource/eczar/400.css'
import '@fontsource/roboto/400.css'
import '@fontsource/roboto/700.css'
import { css, tw } from 'twind/css'

function MyApp({ Component, pageProps }) {
  // tw(
  //   css({
  //     ':global': { body: { '@apply': 'font-sans', },
  //     },
  //   })
  // )

  return <Component {...pageProps} />
}

export default withTwindApp(twindConfig, MyApp)
next.config.js
module.exports = {
  future: { webpack5: true },
}

@twind/next: unable to recover develo

Sorry for the opened issue, if it possible, can you delete #10 and #11. Look like the issue doesn't come from webpack 5, but somewhere else.

Reproduction

Creating a new Next.js project with webpack 5 enable, twind shim version, a cusom _app.js and a custom _document.js (same as the example in README). This is the setting in next.config.js:
module.exports = { future: { webpack5: true, } };

Changing the twind config file or any thrown errors (e.g. returning multiple components) , upon fixing will trigger this error from twind
Error: Error: [LATE_SETUP_CALL] {} at withTwindDocument (node_modules\@twind\next\document\document.cjs:38:27) at withTwindDocument (node_modules\@twind\next\shim\document\document.cjs:32:52)

Next.JS peer dependency needs to be updated to support Next12

Hey all, I'm trying to install @twind/next in an app using NextJS v12. However, this is the error I'm facing during installation:

npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/next
npm ERR!   next@"^12.0.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer next@"10.x || 11.x" from @twind/[email protected]
npm ERR! node_modules/@twind/next
npm ERR!   @twind/next@"*" from the root project

From the error, I'm guessing that the peer dep needs to be updated.

Using shim and avoiding FOUC

In twind docs, it recommends that we add hidden to <html> to avoid flash of unstyled content. The shim should auto-remove this once everything is good.

However, when using hidden with @twind/next, the hidden will never be removed and the page will remain hidden forever

What should I do to avoid FOUC instead?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.