Describe the bug
(This bug also occurs with @sveltejs/adapter-cloudflare@1.0.0, I'm talking about 1.0.0-next.36 because that's what introduced the issue.)
I need a workaround for an ugly Safari bug, which forces me to do some HTML rewriting before I use @html. I use DOMParser.parseFromString and some light DOM manipulation for this. This function is only called when browser from $app/environment is true.
Upgrading to @sveltejs/adapter-cloudflare@1.0.0-next.36 broke the Typescript DOM API:
Error: Argument of type 'HTMLDivElement' is not assignable to parameter of type 'Content'. (ts)
div.textContent = "\n";
child.after(div);
}
That child there is of type Element, and Element.after absolutely should take a HTMLDivElement. Looking up the type definition of child.after in an IDE leads to node_modules/@cloudflare/workers-types/index.d.ts which has the incorrect
declare type Content = string | ReadableStream | Response;
...
interface Element {
...
after(content: Content, options?: ContentOptions): Element;
It seems PR #6917 caused ambient.d.ts referencing Cloudflare's types make them override the DOM API types:
|
/// <reference types="@cloudflare/workers-types" /> |
It seems this only triggers if the tsconfig workspace contains a file that actually imports @sveltejs/adapter-cloudflare. In my case, I have svelte.config.js added to tsconfig so I get useful IDE feedback.
Reproduction
https://github.com/tv42/sveltekit-issue-cloudflare-dom
The latest commit has svelte-check complaining
/blah/bug-dom-worker-2/src/routes/+page.svelte:9:17
Error: Argument of type 'HTMLSpanElement' is not assignable to parameter of type 'Content'. (ts)
span.innerText = "dynamic content";
h1.append(span);
}
You can checkout the commit before it switched to @sveltejs/adapter-cloudflare@1.0.0-next.36, run npm i, and observe npm run check be happy.
Note how triggering this hinges on the commit that edited tsconfig.json.
Logs
No response
System Info
System:
OS: Linux 6.0 NixOS 22.11 (Raccoon) 22.11 (Raccoon)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 36.27 GB / 62.60 GB
Container: Yes
Shell: 5.1.16 - /run/current-system/sw/bin/bash
Binaries:
Node: 16.18.1 - /nix/store/gqbqpgmr7s8b3km14m54ys5kilx0akcc-nodejs-16.18.1/bin/node
npm: 8.19.2 - /nix/store/gqbqpgmr7s8b3km14m54ys5kilx0akcc-nodejs-16.18.1/bin/npm
Browsers:
Firefox: 108.0.1
npmPackages:
@sveltejs/adapter-cloudflare: ^1.0.0-next.36 => 1.0.0-next.36
@sveltejs/kit: ^1.0.0 => 1.0.1
svelte: ^3.54.0 => 3.55.0
vite: ^4.0.0 => 4.0.3
Severity
blocking an upgrade
Additional Information
No response
Describe the bug
(This bug also occurs with
@sveltejs/adapter-cloudflare@1.0.0, I'm talking about1.0.0-next.36because that's what introduced the issue.)I need a workaround for an ugly Safari bug, which forces me to do some HTML rewriting before I use
@html. I useDOMParser.parseFromStringand some light DOM manipulation for this. This function is only called whenbrowserfrom$app/environmentis true.Upgrading to @sveltejs/adapter-cloudflare@1.0.0-next.36 broke the Typescript DOM API:
That
childthere is of typeElement, andElement.afterabsolutely should take aHTMLDivElement. Looking up the type definition ofchild.afterin an IDE leads tonode_modules/@cloudflare/workers-types/index.d.tswhich has the incorrectIt seems PR #6917 caused ambient.d.ts referencing Cloudflare's types make them override the DOM API types:
kit/packages/adapter-cloudflare-workers/ambient.d.ts
Line 1 in 4b7fc72
It seems this only triggers if the tsconfig workspace contains a file that actually imports
@sveltejs/adapter-cloudflare. In my case, I havesvelte.config.jsadded to tsconfig so I get useful IDE feedback.Reproduction
https://github.com/tv42/sveltekit-issue-cloudflare-dom
The latest commit has
svelte-checkcomplainingYou can checkout the commit before it switched to @sveltejs/adapter-cloudflare@1.0.0-next.36, run
npm i, and observenpm run checkbe happy.Note how triggering this hinges on the commit that edited
tsconfig.json.Logs
No response
System Info
System: OS: Linux 6.0 NixOS 22.11 (Raccoon) 22.11 (Raccoon) CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz Memory: 36.27 GB / 62.60 GB Container: Yes Shell: 5.1.16 - /run/current-system/sw/bin/bash Binaries: Node: 16.18.1 - /nix/store/gqbqpgmr7s8b3km14m54ys5kilx0akcc-nodejs-16.18.1/bin/node npm: 8.19.2 - /nix/store/gqbqpgmr7s8b3km14m54ys5kilx0akcc-nodejs-16.18.1/bin/npm Browsers: Firefox: 108.0.1 npmPackages: @sveltejs/adapter-cloudflare: ^1.0.0-next.36 => 1.0.0-next.36 @sveltejs/kit: ^1.0.0 => 1.0.1 svelte: ^3.54.0 => 3.55.0 vite: ^4.0.0 => 4.0.3Severity
blocking an upgrade
Additional Information
No response