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
[assetserver] Inject runtime/IPC into all index html files #2203
[assetserver] Inject runtime/IPC into all index html files #2203
Conversation
Cool, thank you for doing this 🥳 I will try to test it soon |
I need to stop trying to review on the mobile app 😅 |
c89eda2
to
d5dda99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this @stffabi !
b27da7d
to
d3b156d
Compare
@stffabi Is it expected that when my frontend does a fetch request for In this case I'm fetching some HTML components that get injected into the page, and it already has vite; basically there are only certain files I want the script injected onto; and I'm starting to wonder if I should either just do that manually, or if I'm designing my app wrong... |
One more question: Should the runtime and IPC be injected into the root index.html file even if the URL is not |
Yeah that's what this PR should do, it should inject into all html |
@stffabi Thanks. Yeah, I think so:
I think this step is optional, but I already did it, so I'll document it here: add a file called Run Shouldn't IPC+runtime be injected into the root index file regardless of the URL path? Thanks for your help! |
@mholt thanks for this guide. I've just tested it with this PR and everything worked as expected. Both curl I've tested on macOS but wouldn't expect this to differ between platforms. Would it be possible for you to check if you are using the right wails replace in your go.mod? Just to be sure. replace github.com/wailsapp/wails/v2 v2.2.0 => github.com/stffabi/wails/v2 v2.0.0-beta.20.0.20221220124958-d3b156dff78e |
Oh, I think I had the replace wrong 🤦 Thanks Now I'm getting it injected twice: once on the root index.html, and then after my page fetches Thanks! |
@stffabi I had a chance to go over this with @leaanthony which helped clear up my misunderstandings. And I am better equipped to clarify my request :) So, even with this patch, if you do:
you'll notice that the HTTP response has the contents of I think what needs to happen is Wails should be injecting runtime and IPC into the index file regardless of the URL path, or regardless of whether a file is found at the URL path, I mean. Lea pointed to this code:
This is needed, I think, because not all SPAs use hashes for routing. In other words, some use Does that make sense? I'm sorry for the confusion about this issue, I hope this helps clarify what I need, at least, and what I think is correct behavior. :) (PS. I also just barely discovered https://wails.io/docs/guides/frontend#overriding-default-script-injection which allows me to disable auto-inject and manually inject the scripts myself! That's very handy!) |
Perhaps we could introduce a flag to indicate what to do when URLs are "not found"? I'm thinking that an "SPA" mode could be used as well as allowing the dev to supply an html file to serve in this instance. Thoughts? |
@leaanthony Doesn't the AssetServer already invoke a user's handler if a resource isn't found? |
I believe we present a default 404 page. |
@mholt I suspect there's still some confusion about all of this.
What you are seeing that this curl The code you pointed to is before the request is handed over to
I can't see any way how we could detect that Maybe we should meet us all together in a discord channel for a more 1:1 discussion on all of this. Maybe that would be easier for discussing this.
This could be achieved by the developer with an AssetServer middleware and by adding custom |
If the file is not found on the Assets fs.FS it goes to the AssetHandler. |
Agree about the discord chat. Seems like the async chat here is confusing us all :-) Like I was amazed vite returns data on :34115 :-) |
e6493db
to
5ad4ef5
Compare
@mholt - do you think this is good to go as is? |
Sorry I stepped away from this for a while. Once I discovered
But it still seems to be injected by Wails (you can see the script tags twice; the ones at the top are injected): This is confirmed by the console, which says that wails is connected... twice: I might be misunderstanding something about this still... |
It will also be injected into all html files returned when requesting a folder path.
@leaanthony I've just rebased the PR to the master branch. |
5ad4ef5
to
6442de3
Compare
It will also be injected into all html files returned when requesting a folder path.
Fixes #2047