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

v-bind in SSR with dev server fails to resolve imported objects #11273

Open
bcdanieldickison opened this issue Jul 1, 2024 · 3 comments · May be fixed by #11319
Open

v-bind in SSR with dev server fails to resolve imported objects #11273

bcdanieldickison opened this issue Jul 1, 2024 · 3 comments · May be fixed by #11319
Labels
has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working 🔩 p2-edge-case

Comments

@bcdanieldickison
Copy link

bcdanieldickison commented Jul 1, 2024

Vue version

3.4.31

Link to minimal reproduction

Steps to reproduce

When rendering SSR inside of the vite dev server with vite.ssrLoadModule, v-bind inside of <style> fails when referencing an import-ed object from <script setup>. Simply assigning the object to a new const at the script scope works around the issue, as does doing a production SSR build.

App.vue:

<script setup lang="ts">
import Color from './Color'
const C = Color
</script>

<template>
  <h1>Hello</h1>
</template>

<style>
h1 {
  /* this fails: */
  color: v-bind("Color.red");
  
  /* this works: */
  /* color: v-bind("C.red"); */
}
</style>

ssr-fail.js:

import { exit } from 'process'
import { createServer as createViteServer } from 'vite'

const vite = await createViteServer({
  server: { middlewareMode: true },
  appType: 'custom'
})
const { render } = await vite.ssrLoadModule('/src/entry-server.js')
const appHtml = await render('/')
console.log(appHtml)
exit(0)

What is expected?

$ npm test
<h1 style="--7a7a37b1-C\.red:#ff00ee;">Hello</h1>

What is actually happening?

$ npm run test
/Users/daniel/bc/src/ssr-test/src/App.vue:26
    "--7a7a37b1-Color\\.red": $setup.Color.red
                                           ^

TypeError: Cannot read properties of undefined (reading 'red')

System Info

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.50 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.7.2 - /opt/homebrew/bin/node
    npm: 10.8.1 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 17.4.1
    Safari Technology Preview: 18.0
  npmPackages:
    vue: ^3.4.29 => 3.4.31

Any additional comments?

We maintain a design-system module with various constants for color tokens. The most natural way to use these in our app components leads to this error in our dev environment.

@skirtles-code
Copy link
Contributor

This problem does seem to be reproducible using the Playground in SSR mode:

@LinusBorg LinusBorg added 🐞 bug Something isn't working scope: ssr labels Jul 5, 2024
@bcdanieldickison
Copy link
Author

This problem does seem to be reproducible using the Playground in SSR mode:

Thanks! I didn't notice there was an option to enable dev-mode SSR rendering in the playground. I'll add a link to the description.

@codethief
Copy link

This has bitten us multiple times in the past month. While there is a workaround, that doesn't really scale well if you have dozens of v-binds per component (e.g. for theming purposes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working 🔩 p2-edge-case
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants