From c6e0524c061f8a18456858b0e741a5eb7e55bdd6 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 8 Jul 2022 20:53:27 +0000 Subject: [PATCH] make customFetch global (#386) 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. --- generate-wasm-examples/generate_wasm_examples.sh | 7 ++----- templates/example.html | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/generate-wasm-examples/generate_wasm_examples.sh b/generate-wasm-examples/generate_wasm_examples.sh index 34841d0942..80a9841ce8 100755 --- a/generate-wasm-examples/generate_wasm_examples.sh +++ b/generate-wasm-examples/generate_wasm_examples.sh @@ -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 "+++ diff --git a/templates/example.html b/templates/example.html index f7e72e98b2..189561362a 100644 --- a/templates/example.html +++ b/templates/example.html @@ -74,7 +74,7 @@

{{ category.title }} / {{ page.title }}

} }) } - - init(loadingBarFetch); + window.bevyLoadingBarFetch = loadingBarFetch; + init(); {% endblock content %}