Skip to content

Commit

Permalink
make customFetch global (#386)
Browse files Browse the repository at this point in the history
To try and reduce the likelihood of this breaking again we can simply register customFetch globally and use it directly from the window. It still relies on wasm-bindgen not changing a specific line, but at least it's one line instead of 5.

I tested it locally and it works.

Obviously doing things globally isn't ideal, but I renamed it to be a bit more explicit.

I tried simply overriding `fetch` itself globally, but it broke everything.
  • Loading branch information
IceSentry committed Jul 8, 2022
1 parent f1b14f3 commit c6e0524
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions generate-wasm-examples/generate_wasm_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ add_category()
# Patch generated JS to allow to inject custom `fetch` with loading feedback.
# See: https://github.com/bevyengine/bevy-website/pull/355
sed -i.bak \
-e 's/function init(input) {/function init(customFetch, input) { customFetch = customFetch || fetch;/' \
-e 's/input = fetch(/input = customFetch(/' \
-e 's/getObject(arg0).fetch(/customFetch(/' \
-e 's/const imports = getImports();/const imports = getImports(customFetch);/' \
-e 's/function getImports() {/function getImports(customFetch) {/' \
-e 's/getObject(arg0).fetch(/window.bevyLoadingBarFetch(/' \
-e 's/input = fetch(/input = window.bevyLoadingBarFetch(/' \
../../content/examples/$category_slug/$example_slug/$example.js

echo "+++
Expand Down
4 changes: 2 additions & 2 deletions templates/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h2 class="example__title">{{ category.title }} / {{ page.title }}</h2>
}
})
}

init(loadingBarFetch);
window.bevyLoadingBarFetch = loadingBarFetch;
init();
</script>
{% endblock content %}

0 comments on commit c6e0524

Please sign in to comment.