Skip to content

[Bug?]: data attribute set to false || undefined becomes "false"Β #2055

@zhengkyl

Description

@zhengkyl

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Setting a data attribute to false || undefined will lead to "false" in the SSR output.

import { createSignal } from "solid-js";

export default function App() {
  const [falseSignal1] = createSignal(false)
  return (
    <main
      data-false={false || undefined} // "false"
      data-reverse={undefined || false} // "false"
      data-signal={falseSignal1() || undefined} // "false"
      bool:data-bool={false || undefined} // "false"
      
      data-undefined={undefined} // nothing
      data-string={"" || undefined} // nothing
      data-null={null || undefined} // nothing
    >
    why
    </main>
  );
}

Hardcoded false || undefined always seems to appear as "false", but it can be flaky sometimes, maybe HMR or client side navigation instead of SSR work properly.

I have tested in dev and after build, cleared .vinxi cache, tested in bare template and old codebase, updated dependencies to latest.

EDIT:
Something in dom-expressions is changing it to escape(false, true) || escape(undefined, true) which becomes "false" || undefined

Expected behavior πŸ€”

The data attribute should be removed.

Steps to reproduce πŸ•Ή

Steps:

  1. Create new bare solidstart app (pnpm create solid)
  2. Add data-test={false || undefined} to any element
  3. Inspect element
  4. See data-test="false"

Context πŸ”¦

I am using data attributes to apply dynamic tailwind styles. By writing data-[something] to match existence instead of data-[something=true] I type less characters. Removing attribute by setting undefined is common practice, see kobalte code https://github.com/search?q=repo%3Akobaltedev%2Fkobalte%20%7C%7C%20undefined&type=code

Your environment 🌎

"dependencies": {
    "@solidjs/start": "^1.2.1",
    "solid-js": "^1.9.11",
    "vinxi": "^0.5.11"
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions