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

Console warning: using deprecated parameters for the initialization function; pass a single object instead #905

Closed
yescallop opened this issue Nov 6, 2024 · 3 comments · Fixed by #906

Comments

@yescallop
Copy link
Contributor

yescallop commented Nov 6, 2024

When running a Leptos CSR app with Trunk in the browser, I always get this warning in the console:

using deprecated parameters for the initialization function; pass a single object instead

It is triggered by the __wbg_init function in the JS file:

async function __wbg_init(module_or_path) {
    if (wasm !== undefined) return wasm;


    if (typeof module_or_path !== 'undefined') {
        if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
            ({module_or_path} = module_or_path)
        } else {
            console.warn('using deprecated parameters for the initialization function; pass a single object instead')
        }
    }
    ...
}

Because the argument to this function in index.html is a string instead of an object:

import init, * as bindings from '/c6ol-client-27e2b4451d2c072.js';
const wasm = await init('/c6ol-client-27e2b4451d2c072_bg.wasm');

I tracked this down to this commit in wasm-bindgen, which is shipped in v0.2.93 and onwards. The corresponding pull request is rustwasm/wasm-bindgen#3995.

The corresponding code in Trunk are these lines:

import init{import} from '{base}{js}';
const wasm = await init('{base}{wasm}');

I think we can maybe change the second line to pass an object instead of a string, but we need to be careful not to break compatibility with wasm-bindgen before v0.2.93. I might investigate this later and open a PR for this.

@ctron
Copy link
Collaborator

ctron commented Nov 6, 2024

Would previous versions also accept an object?

@ctron
Copy link
Collaborator

ctron commented Nov 6, 2024

Just checked, look like it doesn't. So we indeed need to eval the version.

@ctron ctron closed this as completed in #906 Nov 7, 2024
@robofinch
Copy link

robofinch commented Nov 13, 2024

I don't think this completely fixes the issue. I've been getting this console warning when starting web workers with gloo-worker, and traced it back to a temporary file containing

importScripts("http://localhost:8080/web_worker.js"); wasm_bindgen("http://localhost:8080/web_worker_bg.wasm");

(The exact URLs don't matter.) I'm fairly certain the file was generated by

WasmBindgenTarget::NoModules => format!(
r#"importScripts("./{hashed_js_name}");wasm_bindgen("./{hashed_wasm_name}");"#,
),

wasm_bindgen refers to / runs __wbg_init, so the same issue as above occurs.

Edit: I half take it back, I found where the file was generated in gloo-worker, I'll submit an issue there. Though the above code still should probably use the new format for __wbg_init. Incidentally, the same issue probably appears in

let script = Array::new();
script.push(
&format!(r#"importScripts("{origin}/{name}.js");wasm_bindgen("{origin}/{name}_bg.wasm");"#)
.into(),
);

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 a pull request may close this issue.

3 participants