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

fix: work around safari bug #11601

Merged
merged 7 commits into from
Jan 11, 2024
Merged

fix: work around safari bug #11601

merged 7 commits into from
Jan 11, 2024

Conversation

Rich-Harris
Copy link
Member

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:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Jan 11, 2024

🦋 Changeset detected

Latest commit: 4e84a12

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@Rich-Harris
Copy link
Member Author

Not sure why the tests are failing here, they succeed locally

@Rich-Harris
Copy link
Member Author

Gah, it fails when $env/dynamic/public is imported in hooks.client.js, because the module is evaluated before ${global}.env can be populated.

This might mean we need to wait for env.js to be imported before importing the actual app, which would really suck.

blocks.push(`Promise.all([
import(${s(prefixed(client.start))}),
import(${s(prefixed(client.app))}),
import(${s(`${base}/${options.app_dir}/env.js`)})
Copy link
Contributor

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)

Copy link
Member Author

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.

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 this pull request may close these issues.

3 participants