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

Allow regular script tags #335

Closed
thoughtspile opened this issue Mar 5, 2017 · 3 comments
Closed

Allow regular script tags #335

thoughtspile opened this issue Mar 5, 2017 · 3 comments

Comments

@thoughtspile
Copy link

Would be great to have a way to include a regular script tag (not component definition).
REPL

Some considerations off the top of my head:

  • Maybe only interpret top-level script tags as Svelte code
  • Can svelte code even have an src attribute?

Also, I encountered the issue when using Svelte as a primary server-side renderer:

<html>
  <body>
    <div id="mount"></div>
    <script src="/app.js"></script>
  </body>
</html>

Does component code even make sense when using SSR?

@Conduitry
Copy link
Member

Initial idea - replacing the test here with name in specials && parser.stack.length === 1. I believe this would make <script> and <style> elements only be treated specially if they are on the top level. I don't know whether such a sweeping change is the right way to approach this.

@Rich-Harris
Copy link
Member

I think that approach is good, it's how it behaves in Ractive and it seems to work okay. Was occasionally a source of confusion if you left a preceding element open (since the component script becomes a regular script) but since the parser is now quite strict about that sort of thing it shouldn't be an issue.

Does component code even make sense when using SSR?

Definitely – without it you can't do this sort of thing:

<body>
  <main><App/></main>
  <script src='bundle.js'></script>
</body>

Rich-Harris added a commit that referenced this issue Mar 6, 2017
only process special tags (script, style) when they are top-level
@Rich-Harris
Copy link
Member

Released 1.10.2 with the update: https://svelte.technology/repl/?version=1.10.2&gist=9cfc92380e52f775ca45024146435a47

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

No branches or pull requests

3 participants