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

Using dead view as layout don't let me update DOM #153

Open
hackemateninja opened this issue Nov 11, 2024 · 0 comments
Open

Using dead view as layout don't let me update DOM #153

hackemateninja opened this issue Nov 11, 2024 · 0 comments

Comments

@hackemateninja
Copy link

hackemateninja commented Nov 11, 2024

I have a component name Shell.svelte

<script>
	import {
		Header,
		HeaderNav,
		HeaderNavItem,
		HeaderNavMenu,
		SkipToContent,
		Grid,
		Row,
		Column,
		Content
	} from "carbon-components-svelte";

	let isSideNavOpen = false;
</script>

<Header company="IBM" platformName="Carbon Svelte" bind:isSideNavOpen>
	<svelte:fragment slot="skip-to-content">
		<SkipToContent />
	</svelte:fragment>
	<HeaderNav>
		<HeaderNavItem
			href="/1"
			text="Link 1"
			data-phx-link="redirect"
			data-phx-link-state="push"
		/>
		<HeaderNavItem
			href="/2"
			text="Link 2"
			data-phx-link="redirect"
			data-phx-link-state="push"
		/>
		<HeaderNavItem
			href="/3"
			text="Link 3"
			data-phx-link="redirect"
			data-phx-link-state="push"
		/>
		<HeaderNavItem
			href="/4"
			text="Link 4"
			data-phx-link="redirect"
			data-phx-link-state="push"
		/>
		<HeaderNavItem
			href="/5"
			text="Link 5"
			data-phx-link="redirect"
			data-phx-link-state="push"
		/>
		<HeaderNavItem
			href="/6"
			text="Link 6"
			data-phx-link="redirect"
			data-phx-link-state="push"
		/>
		<HeaderNavItem
			href="/7"
			text="Link 7"
			data-phx-link="redirect"
			data-phx-link-state="push"
		/>
		<HeaderNavItem
			href="/8"
			text="Link 8"
			data-phx-link="redirect"
			data-phx-link-state="push"
		/>
	</HeaderNav>
</Header>

<Content>
	<slot>
		no things here
	</slot>
</Content>

en when I use as layout like this in app.html.heex:

<.flash_group flash={@flash} />
<.svelte name="Shell">
  <%= @inner_content %>
</.svelte>

Works well but when i try to handle an event like this

defmodule SvelteDemoWeb.ExampleTwo do
  use SvelteDemoWeb, :live_view

  def mount(_params, _session, socket) do
    socket =
      assign(socket,
        number: 2
      )

    {:ok, socket}
  end

  def handle_event("increase", _, socket) do
    # This will show in the console when the button is clicked
    IO.inspect(socket.assigns.number)
    {:noreply, assign(socket, :number, socket.assigns.number + 1)}
  end

  def render(assigns) do
    IO.inspect(assigns.number, label: "Rendered number")

    ~H"""
    <div class="flex items-center justify-evenly">
      <div class="">
        <%= @number %>
        <button phx-click="increase">Increase server</button>
      </div>
      <.svelte name="ExampleTwo" props={%{number_live: @number}} socket={@socket} />
    </div>
    """
  end
end

The DOM don't update the number and show me this in the browser

hooks.js:9 Uncaught TypeError: Cannot read properties of undefined (reading 'parentNode')
    at detach (hooks.js:9:10)
    at Object.update (hooks.js:31:21)
    at ViewHook.updated (hooks.js:120:35)
    at ViewHook.__updated (view_hook.js:34:37)
    at view.js:489:55
    at dom_patch.js:79:56
    at Array.forEach (<anonymous>)
    at DOMPatch.trackAfter (dom_patch.js:79:36)
    at dom_patch.js:348:32
    at Array.forEach (<anonymous>)

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

No branches or pull requests

1 participant