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

templates with (inline) template strings breaks bundling of SSR pages #1154

Closed
thescientist13 opened this issue Sep 25, 2023 · 0 comments · Fixed by #1155 or #1120
Closed

templates with (inline) template strings breaks bundling of SSR pages #1154

thescientist13 opened this issue Sep 25, 2023 · 0 comments · Fixed by #1155 or #1120
Assignees
Labels
Milestone

Comments

@thescientist13
Copy link
Member

Summary

Noticed that when bundling an SSR page that itself happened to contain template literal strings, Rollup was breaking.

For example

src/
  pages/
    posts.js
  template/
    app.html

And then app.html might look something like this

<!DOCTYPE html>
<html lang="en" prefix="og:http://ogp.me/ns#">
  <head>
    <title>Some  Title</title>
    <script>
      const message = `The current time is ${new Date().getTime()}`;

      alert(message);
    </script>
  </head>
  <body>
    <page-outlet></page-outlet>
  </body>
</html>

Will result in a parse error from Rollup

SyntaxError: Unexpected token (28:17) in /Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/test/cases/serve.default.ssr/.greenwood/_artists.js
    at pp$4.raise (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:19420:13)
    at pp$9.unexpected (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16714:8)
    at pp$9.semicolon (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16691:66)
    at pp$8.parseVarStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:17122:8)
    at pp$8.parseStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16869:17)
    at pp$8.parseBlock (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:17190:21)
    at pp$5.parseFunctionBody (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:19246:22)
    at pp$8.parseFunction (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:17312:8)
    at pp$8.parseFunctionStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:17012:15)
    at pp$8.parseStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/rollup/dist/es/shared/rollup.js:16901:19) {
  pos: 10688,
  loc: {
    column: 17,
    file: '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/test/cases/serve.default.ssr/.greenwood/_artists.js',
    line: 28
  },
  raisedAt: 10691,
  frame: '26:           <style>*{color:blue}h1{width:50%;margin:0 auto;text-align:center;color:red;}</style>\n' +
    '27:           <script type="module" src="/header.4557af3c.js"></script>\n' +
    '28: <script>const e=`The current time is ${(new Date).getTime()}`;alert(e);\n' +
    '                     ^\n' +
    '29: //# sourceMappingURL=55016989.32ad046b.js.map\n' +
    '30: </script>',
  id: '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/test/cases/serve.default.ssr/.greenwood/_artists.js',
  hook: 'transform',
  code: 'PLUGIN_ERROR',
  plugin: 'commonjs',
  watchFiles: [
    '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/test/cases/serve.default.ssr/.greenwood/_artists.js',
    '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/test/cases/serve.default.ssr/.greenwood/_index.js',
    '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/test/cases/serve.default.ssr/.greenwood/_users.js',
    '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/test/cases/serve.default.ssr/src/pages/index.js',
    '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/test/cases/serve.default.ssr/src/pages/artists.js',
    '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/cli/test/cases/serve.default.ssr/src/pages/users.js'
  ]
}

Details

You'll notice that the parse error happens on a line where a the ` from app.html starts. This is likely an escaping issue with how we are "packing" static templates into SSR pages at build time.

@thescientist13 thescientist13 added this to the 1.0 milestone Sep 25, 2023
@thescientist13 thescientist13 changed the title template or page content with (inline) template strings breaks bundling of SSR pages templates with (inline) template strings breaks bundling of SSR pages Sep 25, 2023
@thescientist13 thescientist13 self-assigned this Sep 25, 2023
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in [Greenwood] Phase 9 - Standards and Conventions Oct 14, 2023
@thescientist13 thescientist13 mentioned this issue Oct 14, 2023
25 tasks
@thescientist13 thescientist13 linked a pull request Oct 14, 2023 that will close this issue
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
1 participant