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

<style> tag support in JSX #136

Open
thescientist13 opened this issue Jan 6, 2024 · 0 comments
Open

<style> tag support in JSX #136

thescientist13 opened this issue Jan 6, 2024 · 0 comments
Labels
feature New feature or request JSX question Further information is requested
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Jan 6, 2024

Summary

Currently there does not seem to be a way to do <style> tags in JSX content.

export default class Header extends HTMLElement {

  connectedCallback() {
    this.render();
  }

  render() {
    return (
      <div>
        <style>
          :host p {
            text-align: 'center';
          }
        </style>
        <header>
          <p>Welcome to my site</p>
        </header>
      </div>
    );
  }
}

customElements.define('app-header', Header);
    [0] file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn/dist/acorn.mjs:3454
    [0]   var err = new SyntaxError(message);
    [0]             ^
    [0] 
    [0] SyntaxError: Unexpected token (12:22)
    [0]     at pp$4.raise (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn/dist/acorn.mjs:3454:13)
    [0]     at pp$9.unexpected (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn/dist/acorn.mjs:750:8)
    [0]     at pp$9.expect (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn/dist/acorn.mjs:744:26)
    [0]     at Parser.jsx_parseExpressionContainer (/Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-jsx/index.js:329:12)
    [0]     at Parser.jsx_parseElementAt (/Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-jsx/index.js:399:32)
    [0]     at Parser.jsx_parseElementAt (/Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-jsx/index.js:391:32)
    [0]     at Parser.jsx_parseElement (/Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-jsx/index.js:436:19)
    [0]     at Parser.parseExprAtom (/Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-jsx/index.js:443:21)
    [0]     at pp$5.parseExprSubscripts (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn/dist/acorn.mjs:2621:19)
    [0]     at pp$5.parseMaybeUnary (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn/dist/acorn.mjs:2587:17) {
    [0]   pos: 198,
    [0]   loc: Position { line: 12, column: 22 },
    [0]   raisedAt: 199
    [0] }
    [0] 
    [0] Node.js v18.12.1
  

You can also the IDE complaining as well
Screenshot 2024-01-06 at 12 43 57 PM

Details

Something like this will work though

const styles = `
  :host p {
    text-align: 'center';
  }
`

export default class Header extends HTMLElement {

  connectedCallback() {
    this.render();
  }

  render() {
    return (
      <div>
        <style>
          {styles}
        <header>
          <p>Welcome to my site</p>
        </header>
      </div>
    );
  }
}

customElements.define('app-header', Header);

Seems like this is the state of things and not sure there's any good solution around it, so not sure what our options are here though, if any?

@thescientist13 thescientist13 added feature New feature or request JSX labels Jan 6, 2024
@thescientist13 thescientist13 added this to the 1.0 milestone Jan 6, 2024
@thescientist13 thescientist13 added the question Further information is requested label Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request JSX question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant