36 lines
1.5 KiB
JavaScript
36 lines
1.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "ServerInsertMetadata", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return ServerInsertMetadata;
|
|
}
|
|
});
|
|
const _react = require("react");
|
|
const _serverinsertedmetadatasharedruntime = require("../../../shared/lib/server-inserted-metadata.shared-runtime");
|
|
// Receives a metadata resolver setter from the context, and will pass the metadata resolving promise to
|
|
// the context where we gonna use it to resolve the metadata, and render as string to append in <body>.
|
|
const useServerInsertedMetadata = (metadataResolver)=>{
|
|
const setMetadataResolver = (0, _react.useContext)(_serverinsertedmetadatasharedruntime.ServerInsertedMetadataContext);
|
|
if (setMetadataResolver) {
|
|
setMetadataResolver(metadataResolver);
|
|
}
|
|
};
|
|
function ServerInsertMetadata(param) {
|
|
let { promise } = param;
|
|
// Apply use() to the metadata promise to suspend the rendering in SSR.
|
|
const { metadata } = (0, _react.use)(promise);
|
|
// Insert metadata into the HTML stream through the `useServerInsertedMetadata`
|
|
useServerInsertedMetadata(()=>metadata);
|
|
return null;
|
|
}
|
|
|
|
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
|
Object.defineProperty(exports.default, '__esModule', { value: true });
|
|
Object.assign(exports.default, exports);
|
|
module.exports = exports.default;
|
|
}
|
|
|
|
//# sourceMappingURL=server-inserted-metadata.js.map
|