-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: work around safari bug #11601
fix: work around safari bug #11601
Conversation
🦋 Changeset detectedLatest commit: 4e84a12 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Not sure why the tests are failing here, they succeed locally |
Gah, it fails when This might mean we need to wait for |
blocks.push(`Promise.all([ | ||
import(${s(prefixed(client.start))}), | ||
import(${s(prefixed(client.app))}), | ||
import(${s(`${base}/${options.app_dir}/env.js`)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does code in the client.app (or start) use the values of env during the import phase? Because that could be affected with this change.
(Thats why i load the env before everything else in my fix attempt https://github.com/bfanger/kit/tree/fix/sveltekit-v2-safari)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start
doesn't, but app
could because hooks are imported eagerly, and your hooks.client.js
could import $env/dynamic/public
.
So our solutions are essentially the same — load env, then load everything else to ensure that evaluation happens in the correct order. Because of preloading it shouldn't really make any observable difference but it's still kinda filthy.
Ref #11364. There is a very serious Safari bug that apparently very few people have encountered outside SvelteKit, possibly because few frameworks use native ESM with top-level await. That is likely to change over time, and I hope Webkit can prioritise a fix for this issue.
In the meantime we have no choice but to work around it. I don't see a better alternative than this PR, which eagerly loads the dynamic
env.js
module when on a prerendered page, such that${global}.env
is populated by the time any user code tries to read it.This is less good than fetching it lazily, and it only mitigates the issue (since top-level await could appear in user code, and it's likely we'll find other uses for it within the framework in future), but for now I think it will have to do.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits