Svelte: Adding a new component in homepage REPL widgets causes scroll jump

Created on 6 Jun 2019  Â·  7Comments  Â·  Source: sveltejs/svelte

Technically this issue probably belongs in the svelte-repl repo, but I'll forget about it if it's there

https://mobile.twitter.com/MohsenKhakbiz/status/1136676705110827008

REPL bug

Most helpful comment

The blocker was me not knowing it existed

All 7 comments

Hi Rich.. I hope this piece of information will be of any help to you to track down this bug.

//ComponentSelector.svelte

``function addNew() { const component = { name: uid++ ?Component${uid}` : 'Component1',
type: 'svelte',
source: ''
};

    editing = component;

    setTimeout(() => {
        // TODO we can do this without IDs
        document.getElementById(component.name).scrollIntoView(false);
    });

```

"document.getElementById(component.name).scrollIntoView(false);" this line seems to be creating that jump in the web page.

Related issue at sveltejs/svelte-repl#9 and PR at sveltejs/svelte-repl#10. I'm not sure what the right approach should be — what's the original intention for the scroll?

@Riyeshp thanks

@mrkishi Without it, if you switch to (or create) a new component, CodeMirror updates the editor content, but retains the old scroll position, which is a bit unsettling

@Rich-Harris Ah! Makes sense! Were there any blockers from using cm.swapDoc and CodeMirror's documents? If not, I can PR that in.

The blocker was me not knowing it existed

I didn't know about swapDoc either. Does that seem like it could also be used to take care of https://github.com/sveltejs/svelte-repl/issues/3 ?

Is this still something we're looking at? And if so, is the PR at sveltejs/svelte-repl#10 still valid for fixing it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

plumpNation picture plumpNation  Â·  3Comments

davidcallanan picture davidcallanan  Â·  3Comments

Rich-Harris picture Rich-Harris  Â·  3Comments

matt3224 picture matt3224  Â·  3Comments

st-schneider picture st-schneider  Â·  3Comments