Repository navigation
Fields API: Add @wordpress/fields-loader and the getFieldsConfig selector - #84323
ntsekouras wants to merge 2 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +119 B (0%) Total Size: 8.38 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
|
Why do we need a fields-loader package? Why is this just not some actions/hooks on core-data? |
getFieldsConfig selector@wordpress/fields-loader and the getFieldsConfig selector
FWIW it mirrors what we do with That said, is the concern the extra package? If yes, another possible home could be the |
|
The one thing that make "views" different is that views is also about preferences to persist the views, but it's close. It is also very close to "CPTs" IMO as most fields are per entity which live in core-data. I think we should ask the question about what we do later when we have "blocks" are loaded in a similar way, or other things as well, think "admin pages" or any other "admin config" thing. Do we have a package for each of these "loaders" or are these part of "core-data" or another package that holds all of these together? I'm a bit conflicted and undecided personally to be honest but I like how you put the selectors/resolvers in core-data and the package is just about the hooks. On the other side, we do have several useEntityProp hooks within core-data for instance. So I guess we have both cases before, what I think we should do is make a decision and stick to it in the future (put it on agents.md or something) and potentially "unify" the approach (deprecations and such) over time. cc @mcsf @oandregal |
|
The one thing that I don't like though is the "loader" in the name. For me this should be just wordpress/fields if we stick with the package. |
Given that most of the meat is in
I don't like it either. Also, can we drop its |
|
Going to close this one for now and regroup on the main prototype PR at #83368 After the past days of work we have landed the PHP fields API in This is less ambitious than what I pushed before: all screens that use DataViews/DataForm (stable, experimental, plus migrate some that were not using usePostFields) add also adding stable client site utils ( |
What?
Part of: #83368 (Stage 1, item 4 of the merge plan)
This PR adds the client side of reading the fields from the server, without any consumer yet.
core-datagets a selector (getFieldsConfig) to fetch the fields from the REST API, and the new bundled package@wordpress/fields-loaderbuilds on it withuseFieldsandloadFields: they request the fields, import the script modules registered along with them and merge their JS parts into the fields, in the order the server lists them.The selector is public because the package is bundled, so it can't unlock a private one(and on an older WP it's simply missing, which the package reports as an error instead of throwing). The package is deliberately not a
wp.*script, since plugins need to bundle it to fall back when the site doesn't have the Fields API yet.Notes
The README describes the
wp-editorattach point from #84078. There's a thread about a lighter one (#83368 (comment)), but it doesn't affect the code here: the loader imports whatever modules the server lists, wherever they're attached, and it doesn't know about the import map.If the attach point changes, the README needs an update on how a plugin screen gets the modules and which globals they can use.
Testing Instructions
Use of AI Tools
Generated with Fable 5.1 and adjusted/reviewed manually.