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

Runes: cannot optionally bind: to a component's prop if not exported #13368

Closed
rgon opened this issue Sep 23, 2024 · 1 comment · Fixed by #14946
Closed

Runes: cannot optionally bind: to a component's prop if not exported #13368

rgon opened this issue Sep 23, 2024 · 1 comment · Fixed by #14946
Assignees

Comments

@rgon
Copy link
Contributor

rgon commented Sep 23, 2024

Describe the bug

When dynamically creating components, we can use a spread operator to pass in props. This allows for complete flexibility when defining a schema that renders components dynamically. The same flexibility is expected when binding 2-way props, when defining, for example, a form's control field (for file upload or processing).

{#each Object.entries(formSchema) as [key, field]}
	<h3 style="display:inline">{field.title}</h3>
	<field.renderer bind:value={formState[key]} bind:control={componentControl[key]} {...field.extraProps}/>
    <!--    ^- if field.renderer doesn't export control, the whole program errors out -->
{/each}

Without runes, we could bind to a non-exported/non-existant property without the whole program erroring out REPL, so we could instantiate a component that only

export let value

or also

export let value
export control
control = { upload() {...}}

In runes mode, however, if the dynamically loaded component has no bindable control export, we get the bind_not_bindable error: REPL

bind_not_bindable
A component is attempting to bind to a non-bindable property control belonging to InputRenderer.svelte (i.e. <InputRenderer bind:control={...}>). To mark a property as bindable: let { control = $bindable() } = $props()

Should this error be, at most, a warning?

Also, if it cannot be fixed, accessing a component's (by value) exported props, to check if it's set, would at least ease porting existing projects, even if it means duplication of code (as in the WORKAROUND REPL below).

Reproduction

Error in Runes mode: REPL

WORKAROUND: specify whether each field renderer has the optional $bindable property REPL

Logs

No response

System Info

System:
    OS: Linux 6.8 Ubuntu 24.04 LTS 24.04 LTS (Noble Numbat)
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    Memory: 9.09 GB / 23.35 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
    pnpm: 9.3.0 - ~/.local/share/pnpm/pnpm
  Browsers:
    Any
  npmPackages:
    svelte: 5.0.0-next.257 => 5.0.0-next.257

Severity

annoyance

@paoloricciuti
Copy link
Member

It might not be exactly a bug but I think we can and should fix it...I think we should just warn if it's not in the list of bindable values but it's in the list of props. Will fix tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants