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 with methods #167

Closed
zigomir opened this issue Dec 9, 2016 · 5 comments · Fixed by #169
Closed

SSR with methods #167

zigomir opened this issue Dec 9, 2016 · 5 comments · Fixed by #169

Comments

@zigomir
Copy link

zigomir commented Dec 9, 2016

I have a simple counter method

<p>Count: {{count}}</p>
<button on:click="increment()">+1</button>

<script>
  export default {
    data () {
      return {
        count: 0
      }
    },
    methods: {
      increment () {
        this.set({count: this.get('count') + 1})
      }
    }
  }
</script>

and unless I remove on:click="increment()" SSR will return:

/Users/zigomir/development/happiness/node_modules/svelte/compiler/svelte.js:7124
					str += `="` + attribute.value.map( chunk => {
					                             ^

TypeError: Cannot read property 'map' of undefined
    at Element.node.attributes.forEach.attribute (/Users/zigomir/development/happiness/node_modules/svelte/compiler/svelte.js:7124:35)

Should this work?

@Rich-Harris
Copy link
Member

Should this work?

Yes! #169. Thanks for raising

@zigomir
Copy link
Author

zigomir commented Dec 9, 2016

Cool, thanks for quick response!

Looking into PR, I'm curious - does or will svelte support picking up after SSR and make DOM interactive automagically?

@Rich-Harris
Copy link
Member

Not yet, no. Svelte currently appends to the target element, so you need to do this sort of thing...

var target = document.querySelector( 'main' );

target.innerHTML = '';
var thing = new Thing({ target });

...which is less than ideal. Hydration is the other half of #1 (see also #148 (comment)), after SSR – we haven't quite figured out the best approach yet.

Rich-Harris added a commit that referenced this issue Dec 9, 2016
@zigomir
Copy link
Author

zigomir commented Dec 9, 2016

I see, thank you!

@Rich-Harris
Copy link
Member

This is fixed in 1.2.2

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 a pull request may close this issue.

2 participants