Store Not Maintaining State Between LiveView Updates #1736
Replies: 8 comments 2 replies
-
Crosspost from that thread: I can't get this to work via AlpineJS v3 either, I was using 2 for a while with Spruce before upgrading to 3 today, and removing Spruce (as it's now in 3). I took the steps from: https://alpinejs.dev/advanced/extending#via-npm I've got an example repo here: https://github.com/joshuataylor/alpinejs3liveview Steps:
Me refreshing the page to show the example: |
Beta Was this translation helpful? Give feedback.
-
It's also not working for me. Tried a basic example from the docs;
|
Beta Was this translation helpful? Give feedback.
-
Can you try doing this in your JS: And seeing if it works for you? |
Beta Was this translation helpful? Give feedback.
-
Sorry, I got mine fixed. Had to run
|
Beta Was this translation helpful? Give feedback.
-
I already have that in my JS. |
Beta Was this translation helpful? Give feedback.
-
@calebporzio Was this moved to a discussion because it was confirmed to not be a bug in Alpine? |
Beta Was this translation helpful? Give feedback.
-
@lukashambsch did you ever figure this out? I think I am having this same issue in my liveview:
After this happens if I go to the console and enter Alpine.start() the state seemingly comes back so it definitely feels like I am losing Alpine. Curious to know if and how you resolved this. |
Beta Was this translation helpful? Give feedback.
-
I have the same issue and cannot figure it out ! my store loses state when Liveview rerender the template on form validation. I will post if I can find any solution. I noticed on my console this error |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Discussed in #1647
Originally posted by lukashambsch June 26, 2021
Versions
Phoenix - 1.5.9
LiveView - 0.15.4
AlpineJS - 3.1.1
Background
I'm using Phoenix LiveView with some Alpine sprinkled in when necessary. I'm not sure if this is an issue with Alpine, an issue with LiveView, a combination of the two, or user error (most likely). One place I'm using Alpine is to allow the user to toggle the left nav. I'm using a basic store to make managing the state easier across components and managing the styling with tailwind classes.
Problem
Everything works great until I assign to the socket. When I do that, the store seems to lose its state and reverts to the default classes. After I assign to the socket, I'm still able to toggle the nav again. It almost seems as if the state is momentarily lost in between live view updates.
The state seems to be maintained in the nav component, but not elsewhere.The state seems to be maintained correctly when in live view components, instead of the layouts, unless it's within the@inner_content
from the live layout template.What I've Tried so Far
I tried the following and had the same problem:
x-data
.x-data
declaration inside the nav.@inner_content
block.Code
Setting up Alpine with LiveView
Starting Alpine
Registering the store
Nav Store
Body component in root liveview layout
Base LiveView Layout
Nav Component
Layout Wrapper Component
Beta Was this translation helpful? Give feedback.
All reactions