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

POC: Leptos with Workers Assets #640

Merged
merged 3 commits into from
Sep 25, 2024
Merged

POC: Leptos with Workers Assets #640

merged 3 commits into from
Sep 25, 2024

Conversation

kflansburg
Copy link
Contributor

@kflansburg kflansburg commented Sep 21, 2024

This introduces a cargo generate template for using Leptos with Workers Assets.

Assets is not yet publicly available, but can be tested in local development.

cc @BrandonDyer64

@kflansburg kflansburg force-pushed the kflansburg/assets-leptos branch 3 times, most recently from 42b08f9 to 489d870 Compare September 22, 2024 01:57
@kflansburg kflansburg force-pushed the kflansburg/assets-leptos branch from 489d870 to 11f00cc Compare September 22, 2024 02:13
@avsaase
Copy link
Contributor

avsaase commented Sep 23, 2024

Is Worker Assets an upcoming feature? Is there more info about it somewhere?

@petebacondarwin
Copy link

@avsaase - shh. It's a secret 😄 - wait till later this week.

@kflansburg kflansburg marked this pull request as ready for review September 24, 2024 14:07
@kflansburg kflansburg merged commit 566166f into main Sep 25, 2024
6 checks passed
@kflansburg kflansburg deleted the kflansburg/assets-leptos branch September 25, 2024 15:39
@BrandonDyer64
Copy link
Contributor

Love it!

renovate bot referenced this pull request in spiraldb/vortex Sep 26, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [worker](https://redirect.github.com/cloudflare/workers-rs) |
workspace.dependencies | patch | `0.4.0` -> `0.4.1` |

---

### Release Notes

<details>
<summary>cloudflare/workers-rs (worker)</summary>

###
[`v0.4.1`](https://redirect.github.com/cloudflare/workers-rs/releases/tag/v0.4.1)

[Compare
Source](https://redirect.github.com/cloudflare/workers-rs/compare/v0.4.0...v0.4.1)

#### What's Changed

- Add
[template](https://redirect.github.com/cloudflare/workers-rs/tree/main/templates/leptos)
for using [Leptos](https://leptos.dev/) with Workers Assets by
[@&#8203;kflansburg](https://redirect.github.com/kflansburg) in
[https://github.com/cloudflare/workers-rs/pull/640](https://redirect.github.com/cloudflare/workers-rs/pull/640)
- Add API for [Rate
Limiter](https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/)
bindings by [@&#8203;kflansburg](https://redirect.github.com/kflansburg)
in
[https://github.com/cloudflare/workers-rs/pull/603](https://redirect.github.com/cloudflare/workers-rs/pull/603)

**Full Changelog**:
cloudflare/workers-rs@v0.4.0...v0.4.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/spiraldb/vortex).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44MC4wIiwidXBkYXRlZEluVmVyIjoiMzguODAuMCIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AiLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@Boscop
Copy link

Boscop commented Oct 3, 2024

@kflansburg Thanks for this!
I just tried it locally with npx wrangler dev, it tries to load the wasm and js files from the wrong URLs, any idea why?:

[wrangler:inf] GET / 200 OK (2ms)
[wrangler:inf] GET /pkg/leptos_worker.js 404 Not Found (4ms)
[wrangler:inf] GET /pkg/leptos_worker.wasm 404 Not Found (3ms)
[wrangler:inf] GET /favicon.ico 200 OK (4ms)
[wrangler:inf] GET /pkg/leptos_worker.js 404 Not Found (2ms)

Btw, I had to change

[build]
command = "cargo leptos build --release && LEPTOS_OUTPUT_NAME=start-axum worker-build --release --features ssr"

to

[build]
command = "cargo leptos build --release && worker-build --release --features ssr"

to make it build on windows. but I set the env var LEPTOS_OUTPUT_NAME=start-axum in my console before running npx wrangler dev, so this can't be the reason why it's fetching the assets from the wrong URLs, right?

@kflansburg
Copy link
Contributor Author

Can you confirm that you are using the latest version of wrangler? I think npx is supposed to do that, but I've had trouble in the past.

@Boscop
Copy link

Boscop commented Oct 5, 2024

@kflansburg Yes, I literally just updated wrangler before running this.
I have it installed globally so I ran it without npx, but yeah I just updated it :)

@kflansburg
Copy link
Contributor Author

Ok, I did run into something like this, I don't know how you manage node, but can you try to update to latest node / try a fresh node environment. That fixed it for me.

@gembleman
Copy link

gembleman commented Nov 3, 2024

The environment variables were set incorrectly.

2YZeky1V2y

lhflWcVMBx

The web browser wants "leptos_worker", but the pkg folder contains a "start-axum" file.

So, changed output-name.

#Cargo.toml
[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "start-axum"

Or, replace the LEPTOS_OUTPUT_NAME environment variable with leptos_worker.
Of course, after you're done editing, don't forget to delete the existing build and public folders.

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

Successfully merging this pull request may close these issues.

6 participants