Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[AssetMapper] Add support for loading JSON using import statements#61133

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
nicolas-grekas wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromnicolas-grekas:am-json

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedJul 16, 2025
edited
Loading

QA
Branch?7.4
Bug fix?no
New feature?no
Deprecations?no
Issues-
LicenseMIT

This is inspired byhttps://web.dev/blog/json-imports-baseline-newly-available

Modern browserssupport loading JSONs via theimport data from './foo.json' with {type: 'json'} syntax. While this has been promoted as a new baseline, that's still not widely supported.

This PR proposes to add support for a more portable alternative usingimport jsonPromise from './foo.json' instead, with some server-side assisted loader.
On the client-side, one could then use the imported data by awaiting it first (the import returns a Promise):
json = await jsonPromise

Note that we already support importing css via import statements.

Native support forimport './foo.css' with {type: 'css'} exists, but that'seven less available.

smnandre reacted with rocket emoji
Kocal

This comment was marked as resolved.

@Kocal
Copy link
Member

Kocal commentedJul 16, 2025
edited by nicolas-grekas
Loading

Switched to a project with AssetMapper correctly installed, the following code

importjsonfrom'./foo.json'with{type:'json'};console.log(json)

with the patch suggested in#61133 (review) correctly resolves the JSON

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedJul 16, 2025
edited
Loading

This PR is about this:

-import json from './foo.json' with {type: 'json'};+import jsonPromise from './foo.json';

and then (note the await):

console.log(awaitjsonPromise);
Kocal reacted with thumbs up emoji

@Kocal
Copy link
Member

Ah, fine then

@nicolas-grekas
Copy link
MemberAuthor

We should skip using the loader whenwith {type: 'json'}; is in use (same for css BTW).

Kocal and smnandre reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@KocalKocalKocal approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

3 participants
@nicolas-grekas@Kocal@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp