Skip to content

Conversation

@jhwz
Copy link
Contributor

@jhwz jhwz commented Feb 17, 2025

Before submitting the PR, please make sure you do the following

closes #15316

Not super efficient because we're duplicating the expression, the actual issue is likely something else entirely! I'm not at all familiar with the codebase so not going to look much further but this may give you a start.

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2025

🦋 Changeset detected

Latest commit: 817cf1a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@15317

/** @import { SourceLocation } from '#shared' */
/** @import { ComponentClientTransformState, ComponentContext } from '../types' */
/** @import { Scope } from '../../../scope' */
import { escape_html } from '../../../../../escaping.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { escape_html } from '../../../../../escaping.js';

This doesn't seem to be used right?

get_attribute_name,
build_attribute_value,
build_class_directives,
build_set_attributes,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
build_set_attributes,

This doesn't seem to be used right?

build_set_attributes,
build_style_directives,
build_set_attributes
get_attribute_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get_attribute_name

This doesn't seem to be used right?

build_set_attributes
get_attribute_name
} from './shared/element.js';
import { visit_event_attribute } from './shared/events.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { visit_event_attribute } from './shared/events.js';

This doesn't seem to be used right?

);

if (is_select_with_value) {
let { value } = build_attribute_value(attribute.value, context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm i don't think this is the right fix: this is basically doing the same thing it would do anyway without checking if metadata.has_call to get_expression_id.

I think a more thoughtful solution would be to figure out why the expression is not there (most likely we need to create a $0 which is a derived). Let me try to take a look so that i can guide you better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok i've explored this a bit more and there are a couple of things:

  1. we could fix it with something similar to this but instead of rerunning build_attribute_value I would just return the non_memoized value from the function too and use that...this lead me to the next point.
  2. This is not the only place where a bug similar to this exists. For example if you do something like this
<input autofocus={should_focus()} />

it will also error out so we should fix this too.

However fixing it this way could lead to an unexpected behaviour where the function will be called twice the first time (once to initialise it and once in the template effect). So i wonder if we should find a way to access the expressions and pass them in from autofocus and init_select.

P.s. we should also add a test for both this cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so the problematic ones are

  • autofocus
  • muted
  • select value

i think the best course of action in this case would be to check within the memoize function passed as argument to build_attribute_value if there's the need for this functions and in that case instead of calling get_expression_id we return initialize add a new derived to the init and return that id from the memoize.

The downside of this is that when we then pass that derived to template_effect we would be unnecessarily create a derived of a derived but i think it's probably fine.

@paoloricciuti
Copy link
Member

@jhwz do you have capacity to fix this properly? I think we should try to fix it asap

@jhwz
Copy link
Contributor Author

jhwz commented Feb 17, 2025

I think it's a bit out of my depth, I'm not familiar enough with the codebase. Feel free to close this and open another PR.

@paoloricciuti
Copy link
Member

I think it's a bit out of my depth, I'm not familiar enough with the codebase. Feel free to close this and open another PR.

It's close enough to your solution if you want to try...I don't know when I'll have time to open another pr if you want to try in the meantime. Otherwise I'll try to open a new PR adding you as co author 😉

@jhwz
Copy link
Contributor Author

jhwz commented Feb 17, 2025

I'll see what I can do!

@paoloricciuti
Copy link
Member

@jhwz opened #15326 as an alternative, added you as a co-author

@jhwz jhwz closed this Feb 18, 2025
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 this pull request may close these issues.

ReferenceError: $0 is not defined

2 participants