Skip to content

Commit

Permalink
[Float][Fizz][Static] add importMap option to Fizz and Static serve…
Browse files Browse the repository at this point in the history
…r renderers (#27260)

Import maps need to be emitted before any scripts or preloads so the
browser can properly locate these resources.

Unlike most scripts, importmaps are singletons meaning you can only have
one per document and they must appear before any modules are loaded or
preloaded. In the future there may be a way to dynamically add more
mappings however the proposed API for this seems likely to be a
javascript API and not an html tag.

Given the unique constraints here this PR implements React's support of
importMaps as the following

1. an `importMap` option accepting a plain object mapping module
specifier to path is accepted in any API that renders a preamble (head
content). Notably this precludes resume rendering because in resume
cases the preamble should have already been produced as part of the
prerender step.
2. the importMap is stringified and emitted as a `<script
type="importmap">...</script>` in the preamble.
3. the importMap is escaped identically to how bootstrapScriptContent is
escaped, notably, isntances of `</script>` are escaped to avoid breaking
out of the script context

Users can still render importmap tags however with Float enabled this is
rather pointless as most modules will be hoisted above the importmap
that is rendered. In practice this means the only functional way to use
import maps with React is to use this config API.

DiffTrain build for commit 9d4582d.
  • Loading branch information
gnoff committed Aug 24, 2023
1 parent 5a71bfb commit 2931c47
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23977,7 +23977,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-canary-b4cdd3e89-20230823";
var ReactVersion = "18.3.0-canary-9d4582dff-20230824";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8612,7 +8612,7 @@ var devToolsConfig$jscomp$inline_1029 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-b4cdd3e89-20230823",
version: "18.3.0-canary-9d4582dff-20230824",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1228 = {
Expand Down Expand Up @@ -8643,7 +8643,7 @@ var internals$jscomp$inline_1228 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-b4cdd3e89-20230823"
reconcilerVersion: "18.3.0-canary-9d4582dff-20230824"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1229 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9038,7 +9038,7 @@ var devToolsConfig$jscomp$inline_1071 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-b4cdd3e89-20230823",
version: "18.3.0-canary-9d4582dff-20230824",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1269 = {
Expand Down Expand Up @@ -9069,7 +9069,7 @@ var internals$jscomp$inline_1269 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-b4cdd3e89-20230823"
reconcilerVersion: "18.3.0-canary-9d4582dff-20230824"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1270 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-canary-b4cdd3e89-20230823";
var ReactVersion = "18.3.0-canary-9d4582dff-20230824";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-b4cdd3e89-20230823";
exports.version = "18.3.0-canary-9d4582dff-20230824";
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-b4cdd3e89-20230823";
exports.version = "18.3.0-canary-9d4582dff-20230824";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b4cdd3e8922713f8c9817b004a0dc51be47bc5df
9d4582dffdea5b4dcb6a6093ea848d15423c7701

0 comments on commit 2931c47

Please sign in to comment.