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

SX: Improve suggested stylesheet name #1288

Closed
michalsanger opened this issue Nov 8, 2020 · 2 comments · Fixed by #1364
Closed

SX: Improve suggested stylesheet name #1288

michalsanger opened this issue Nov 8, 2020 · 2 comments · Fixed by #1364
Labels
enhancement New feature or request

Comments

@michalsanger
Copy link
Contributor

When an invalid classname is used like here:

<button
  className={tailwind('bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounde')}
  type="button"
>
  Button
</button>

The error is thrown:
Invariant Violation: SX was called with 'rounde' stylesheet name but it doesn't exist. Did you mean 'py-2' instead?

Which is not really helpful, we could do better:
Invariant Violation: SX was called with 'rounde' stylesheet name but it doesn't exist. Did you mean 'rounded' instead?

SX takes suggestions only from the current sx.create call, but for SX Tailwind where we have a limited set of classnames, this set could be used for suggestions.

Could @adeira/sx provide something like registerSuggestions(classNames: Set<string>): void?

@michalsanger michalsanger added the enhancement New feature or request label Nov 8, 2020
@mrtnzlml
Copy link
Member

mrtnzlml commented Nov 8, 2020

@michalsanger Shouldn't the tailwind Babel plugin or sx-tailwind take care of this and validate it? I don't think we should change SX in this case. Would it be possible to check if the class names inside tailwind() call are correct before giving it to SX? 🤔

@michalsanger
Copy link
Contributor Author

When you are using the Babel plugin you actually never execute the tailwind function. So it has to be the Babel plugin who will take care of announcing the error to developer. But it can only throw error or log into console. If the error is thrown, Next fails with Internal error. If it logs into console, I'm afraid it will be hidden. The best DX provides the Next.js error, but for that I need the error to be thrown from the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants