Skip to content

Inconsistent call of onrender #177

@nikku

Description

@nikku

The generator allows target to be optional when instantiating a component (cf. https://github.com/sveltejs/svelte/blob/master/src/generate/index.js#L445).

It will always call onrender though, whether or not the component was mounted or not (cf. https://github.com/sveltejs/svelte/blob/master/src/generate/index.js#L461).

Expected Behavior

  • On render is only called when the component is mounted to the DOM for the first time

Example

For a component like this:

FOO

<script>
export default {
  onrender() { ... }
}
</script>

the generator will currently create the following code snippet:

function SvelteComponent(options) {
       ...

	if (options.target) this._mount(options.target);

	if (options.root) {
		options.root.__renderHooks.push({ fn: template.onrender, context: this });
	} else {
		template.onrender.call(this);
	}

        ....
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions