Reload scripts#9977
Conversation
🦋 Changeset detectedLatest commit: 1d667f8 The changes in this PR will be included in the next version bump. 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 |
|
@OliverSpeir, I'm sure you are aware that adding ... works just fine with Astro. After adding This could be very confusing for users. In fact, we can't reload bundled module scripts anyway. Imho we should better warn users when they try to reload a bundled module script. What do you think? Up to now, we do not have error messages in the browser. Is there a chance to detect this server side? |
I thought about this, adding a check for this is possible and probably could be done for both Do you think there's a way we could inform the user better that adding this property makes it an |
|
At this time of day, my brain is too slow. You are correct that any attribute other than So yes, it's not an astro-data-reload problem, it's an auto-inlining/bundling-is-confusing-and-may-break-things problem. |
Co-authored-by: Martin Trapp <94928215+martrapp@users.noreply.github.com>
Ah this is something I forgot about, I should check this, does the src need to be remote for this condition? I honestly forgot about
Yeah this will be something to be aware of for sure, although Also something I just thought about is there's intellisense auto complete for |
martrapp
left a comment
There was a problem hiding this comment.
Sorry for blocking, but I'm having doubts about the name right now. I would like to discuss with Erika/Matthew whether it is perfect or not so good to use reload as a name for both opt-in on re-execution of scripts and opt-out from view transitions on links.
Pro for same term:
- less cluttered name space
- no risk of confusion: opt-out only for links, re-execution only for scripts
Contra:
- not so simple to describe, e.g. in VS-Code popups "on , , and : opt out from view transitions, on <script> elements opt-in to re-execution during view transitions"
|
I see your point that makes sense! Never thought of it like that, definitely happy to change it to anything else. I went with data-astro-reload because you opt out of view transitions' default behavior with it, but I'm not tied to it. |
|
Yeah I think it makes sense to give this a different name given that it's not the same thing. |
|
@bluwy brought up a good point, do we know if scripts (I'm thinking) 3rd party that really need this? Or do we have support threads of people who needed it? Although it sounds fine, and like something people might run into, I'm not super comfortable with releasing a feature until we know for sure that people have ran into a problem. |
It's hypothetical, I mean I'll use it but I could also work around it. I'm sure there are some 3rd party packages out there though. In the initial issue @matthewp and @martrapp agreed to it, and thats why I submit this PR. I'll understand of course if we decide not to add it, but given that this is restoring a previous functionality of Astro's I think it would be nice to have. Polluting the window, and not having functions execute after every transitions unnecessarily seems like a valid use case to me. I haven't done the math, but wouldn't there be some concern about consuming memory or slowing down mobile devices if they have transitioned to many pages on a site (and thus accumulated many scripts listening for life cycle events)? |
Im currently running into this issue. Need to include an iframe on my site. Iframe is given to me by a 3rd party. 3rd party gives me a script to include that finds an link they provided and injects iframe. Then it uses iframe resizer to size the iframe. Without this fix, if a user is on the page that contains the iframe and then clicks on a link that takes them to the same page, the script does not load. |
|
We discussed it and are fine with releasing this feature. We want a different name though. I think presently the best we've thought of is |
|
rerun is nice 👍 will do |
|
It's good to give different things different names. My main motivation for #10094 and withastro/compiler#965 was to improve errors/warnings to inform users that (what is now called) data-astro-rerun will not work with external ESM scripts. I plan to close those, but i still would like to see some way to warn users. @matthewp & @bluwy: What would be the best approach to just error when data-astro-rerun is set on a |
|
One nice piece of this could be a linting rule @martrapp Similar to this one: withastro/compiler#970 |
Hello Oliver, thank you very much for pointing this out! I wasn't aware of withastro/compiler#970. The warning from withastro/compiler#965 could well belong there! |
bluwy
left a comment
There was a problem hiding this comment.
LGTM! I forgot to reply here, but yeah I've talked with Matthew that the usecase you explained makes sense to me.
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
natemoo-re
left a comment
There was a problem hiding this comment.
Blocking until minor release merge day since GitHub Actions isn't working on the fork 😭

Changes
Adds ability to add
data-astro-reloaddata-astro-rerunto inline scripts so they will be re-executed after view transitionIssue #9798 is related, in it both Mathew and Martin agreed this would be acceptable change
Testing
Didn't add tests because this is very small change, but happy to add if someone thinks its needed
Docs
This should be documented
/cc @withastro/maintainers-docs