Skip to content

Conversation

shjyh
Copy link

@shjyh shjyh commented Jan 13, 2024

Dynamically setting env.SSR enables the framework to use different logic codes in SSR and CSR

for example:

// v-ifdef SSR
import db from "./db"
// v-endif

export default function findProduct() {
  // v-ifdef SSR
  return db.findProduct()
  // v-else
  return fetch("/api/product/search).then(res=>res.json())
  // v-endif
}

shjyh added 2 commits January 13, 2024 10:18
Dynamically setting env.SSR enables the framework to use different logic codes in SSR and CSR
},
transform: (code, id) => ctx.transform(code, id),
transform: (code, id, SSR) => {
ctx.env.SSR = SSR
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not like this?

transform: (code, id, { ssr }) => {
    ctx.env.SSR = !!ssr
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my mistake, it should be like this

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

Successfully merging this pull request may close these issues.

2 participants