Closed darylknight closed 2 years ago
What happens if you remove all of the href="#"
attributes?
Then it's not recognised as something you can click on, and does nothing. It also doesn't work in 1.9.0 if I convert those a
tags to button
s
The recipe at https://putyourlightson.com/sprig/cookbook#pagination is on the latest version of Sprig and working fine. Can you test on your end using the recipe and then compare the differences? Also be sure to look out for errors in the browser console and network tab.
Looks like it basically all works ok (even with a href="#"
, without converting them to button
s) if I take the map out, by commenting out {{ map.tag() }}
.
Looping in @lindseydiloreto - could either of you think of something that changed in 1.9.0 that would break the pagination if there's a Google Map on the page?
Maybe something changed in htmx, you could try loading version 1.5.0 to see if that makes a difference. https://unpkg.com/htmx.org@1.5.0/dist/htmx.min.js
I'm about 80% certain that it's not a problem with Google Maps, though I'm not sure I know enough about Sprig to be helpful.
You can try (1) commenting out the entire map section, and (2) ditching the htmx:afterSettle
event.
Let us know if you're still having problems after removing those two things.
Yep, just tested it again, all on Sprig 1.10.4:
{{ map.tag() }}
from the code, pagination works again. That's why I looped in Lindsey. Although why that would be the case between 1.8.1 and 1.9.0+ I don't know.htmx.on('htmx:afterSettle', function(event) { googleMaps.init('projects-map'); });
is removed, but the map is left in, pagination is brokenSounds like you're going have to examine the JS code run by the maps tag to see why it conflicts with htmx. Are no errors reported in the console?
No, there are no errors in the javascript console or in Craft
For what it's worth - this is still broken in the latest version of Sprig. I've been doing more testing for a few hours this morning, but am currently having to still leave Sprig at 1.8.1 to get it to work.
What is weird, is that it seems to all work fine if I have "roughly less than 150" entries - but at some point at 100+, changing the filters just does nothing. No errors normally selecting something in the dropdown filters the map, but at an unspecified amount of entries, that interactivity stops working and doesn't seem to make any kind of HTML call. Could there be something in Sprig (or again, in combination with Google Maps) that makes it stop working if the query is too long, or too large?
I believe there is a known issue with the Google Maps plugin, perhaps https://github.com/doublesecretagency/craft-googlemaps/issues/52?
Thanks Ben - that's good to know. However, fixing Google Maps at 4.1.4 and updating Sprig to latest still has the same results (but again, it works fine if the map isn't rendered, so I doubt it's just Sprig). Will leave it alone for another few months and see if anything changes in Craft 4.
Maybe there's something else at play here, but I remember that @lindseydiloreto was working on a fix for another similar issue.
@bencroker is correct, this is probably more of a Google Maps issue than a Sprig issue (though it's still not 100% certain).
We ran into a problem where someone had an insane amount of markers (thousands), each with an attached info window. Prior to v4.1.5, all of the info window data was being compacted into the data-dna
of the map container. Unfortunately, this caused a conflict with Sprig... It made the div
tag absolutely enormous, and Sprig stopped processing it (similar to what you described).
So in v4.1.5, we refactored how info windows are handled. The pre-rendered HTML for info windows is no longer stored within the data-dna
attribute, those snippets are now stored outside of the div
in a simple JavaScript variable.
Unfortunately, this introduced a couple of minor regression bugs. With the exception of one, all the regression issues have been fixed. But this one might be a little more complicated to sort out.
Due to timing and other factors, we were pushed to update the Google Maps plugin to be compatible with Craft 4, without having a chance to properly fix this issue first. When a fix for this is introduced, it will likely only be available on Craft 4.
@darylknight I will ping you via Discord DM to figure out what the best next step is. At some point we will be releasing a proper fix for this issue, but that may still be several weeks away.
Thanks both! Chatted to Lindsey on Discord and decided to leave it on Sprig 1.8.1 and Google Maps 4.1.4 for now, until GM is updated for Craft 4. After that I'll revisit this and see if it's still a problem on the latest version of both plugins or if the updates fix it.
@darylknight This is fixed in v4.2.3 of the Google Maps plugin. As noted earlier, it requires Craft 4.
Go ahead and update when you get a chance, let me know if i missed anything. 👍
Thanks Lindsey!
I've updated my code example in the original post (and stripped it down as much as possible).
Ok, I'm all updated to Craft 4 and the latest versions of both plugins, still having the same problem. I think I've tracked it down to an inconsistency between the required query for the two kinds of data I'm trying to display.
For context, here's the URL this relates to: https://www.solvenergy.com/projects (this live page is still on Craft 3 using the combination of plugins that still works). Scroll down to the map section with the filter bar.
.all()
on the query (docs).all()
on the entry query (docs)So after updating everything, here's what I've tried:
Current code version - includes .limit(10) on the pagination query
If I remove the .limit(10)
from the pagination query:
If I remove .limit(10)
from the pagination query, and add limit:10,
to queryParams
at the top of the page:
If I update these two lines and move the .all()
call, and keep the set entryQuery
line as it is, then we're back to pagination not working (when it worked in Sprig 1.8.1)
{% set locations = craft.entries(queryParams).projectAddress(mapSearchParams).all() %}
{% set map = googleMaps.map(locations, mapRenderOptions) %}
So... I've spent probably 20-30 hours trying to fix this since the Sprig update to 1.9.0 now - I have no idea what changed, but something in that update broke the pagination here. I can't ask you two to trawl through the code to work out what's going on either.
I guess the simplest question is whether this design / layout is practical with these two plugins anymore? Should I just separate these two things so that the map always shows all entries, and the list view underneath is filterable?
My guess is that the response is so large that Sprig is choking during the parsing process. I'm seeing upwards of 2 MB to load all map markers, which seems excessive (and slow). This might be a Sprig issue, but I'd start by figuring out whether those responses can be optimised, which I'm guessing is on the Google Maps plugin.
That's possible. I've just realised we're using pretty much exactly the same code on the homepage of danco-group.com, and that has a map that shows all entries, with a paginated list underneath. That's on Google Maps 4.1.9 / Sprig 1.13.0 and it works fine with the same pagination. Only 35 entries though.
@darylknight Not sure if this exactly helps you, but I'm currently working on a project which has a map (showing all results) alongside of a paginated set of results (limit 10). To pull that off, we cloned the query to have paginated and non-paginated queries.
{# Split into parallel queries #}
{% set fullQuery = clone(query) %}
{% set paginatedQuery = query.limit(10) %}
Thanks Lindsey. I've just tried that and have the same result - pagination scrolls back up the page, and the filters don't do anything.
Describe the bug
I'm sorry I can't give a huge amount of detail, but I've just gone through the past 5 versions of Sprig to work out where it happened. In 1.8.1 our code for displaying a paginated list of entries (also displayed on a Google Maps plugin map) worked fine. Since updating to 1.9.0 (and 1.9.1, 2, 3). clicking the pagination buttons just scrolls to the top of the page instead of paginating the sprig list.
Wrapper template
_includes/projectsMap
Expected behaviour
Pagination should switch pages without refreshing the page, like Sprig pagination normally does. Works fine on 1.8.1. In 1.9.0+, clicking a pagination number scrolls the page up (because of the #), but doesn't paginate.
Versions