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

SSR ignores static component properties #817

Closed
martinandert opened this issue Sep 4, 2017 · 3 comments
Closed

SSR ignores static component properties #817

martinandert opened this issue Sep 4, 2017 · 3 comments
Labels
Projects
Milestone

Comments

@martinandert
Copy link
Contributor

Example that does work when rendered client-side, but not on the server ("Hello, undefined!"):

<!-- App.html -->
<h1>Hello, {{name}}!</h1>
<Other />

<script>
  import Other from './Other.html';
	
  export default {
    data() {
      return {
        name: Other.NAME
      };
    },
		
    components: { Other }
  };
</script>
<!-- Other.html -->
<p>How are you today?</p>

<script>
  export default {
    setup(Component) {
      Component.NAME = 'world';
    }
  };
</script>

Perhaps there's a reason static properties are ignored for SSR, or maybe I'm just missing something obvious.

@Rich-Harris
Copy link
Member

I think this is a bug — we should probably run setup in SSR mode. It might cause some confusion if people are using setup to e.g. wrap client-side component methods... anyone have ideas for how we could mitigate that?

@Rich-Harris Rich-Harris added the bug label Sep 4, 2017
@arxpoetica arxpoetica added this to Triage in Roadmap Jan 10, 2018
@arxpoetica arxpoetica moved this from Triage to Immediate priorities in Roadmap Jan 10, 2018
@Conduitry
Copy link
Member

Do we want it to be available somehow to the component behavior code whether it was compiled in DOM or SSR mode? Is that a terrible idea?

@Rich-Harris
Copy link
Member

I'm going to close this as it's fixed in v3. There's no longer a setup hook — instead, a component can have named module-level exports, so it'd be done like this:

<script>
  import Other, { NAME } from './Other.html';
</script>

<!-- App.html -->
<h1>Hello, {NAME}!</h1>
<Other />
<!-- Other.html -->
<script context="module">
  export const NAME = 'world';
</script>

<p>How are you today?</p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Roadmap
  
Immediate priorities
Development

No branches or pull requests

3 participants