Skip to content

Commit

Permalink
The implementation ended up not merging the boundary resource concept…
Browse files Browse the repository at this point in the history
… with hoistable state due to the very different nature in which these things need to hoist (one during task completion and the other during flush but only when flushing late boundaries). Given that I've gone back to resource specific naming rather than calling it BoundaryState.
  • Loading branch information
gnoff committed Oct 17, 2023
1 parent 86083a5 commit 81d6691
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 59 deletions.
44 changes: 22 additions & 22 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,7 @@ function pushLink(
props: Object,
resumableState: ResumableState,
renderState: RenderState,
boundaryState: null | BoundaryState,
boundaryState: null | BoundaryResources,
hoistableState: HoistableState,
textEmbedded: boolean,
insertionMode: InsertionMode,
Expand Down Expand Up @@ -2334,7 +2334,7 @@ function pushStyle(
props: Object,
resumableState: ResumableState,
renderState: RenderState,
boundaryState: null | BoundaryState,
boundaryState: null | BoundaryResources,
textEmbedded: boolean,
insertionMode: InsertionMode,
noscriptTagInScope: boolean,
Expand Down Expand Up @@ -3286,7 +3286,7 @@ export function pushStartInstance(
props: Object,
resumableState: ResumableState,
renderState: RenderState,
boundaryState: null | BoundaryState,
boundaryState: null | BoundaryResources,
hoistableState: HoistableState,
formatContext: FormatContext,
textEmbedded: boolean,
Expand Down Expand Up @@ -3932,7 +3932,7 @@ export function writeCompletedBoundaryInstruction(
resumableState: ResumableState,
renderState: RenderState,
id: number,
boundaryResources: BoundaryState,
boundaryResources: BoundaryResources,
): boolean {
let requiresStyleInsertion;
if (enableFloat) {
Expand Down Expand Up @@ -4263,7 +4263,7 @@ function hasStylesToHoist(stylesheet: StylesheetResource): boolean {

export function writeResourcesForBoundary(
destination: Destination,
boundaryResources: BoundaryState,
boundaryResources: BoundaryResources,
renderState: RenderState,
): boolean {
// Reset these on each invocation, they are only safe to read in this function
Expand Down Expand Up @@ -4569,7 +4569,7 @@ const arrayCloseBracket = stringToPrecomputedChunk(']');
// [["JS_escaped_string1", "JS_escaped_string2"]]
function writeStyleResourceDependenciesInJS(
destination: Destination,
boundaryResources: BoundaryState,
boundaryResources: BoundaryResources,
): void {
writeChunk(destination, arrayFirstOpenBracket);

Expand Down Expand Up @@ -4762,7 +4762,7 @@ function writeStyleResourceAttributeInJS(
// [["JSON_escaped_string1", "JSON_escaped_string2"]]
function writeStyleResourceDependenciesInAttr(
destination: Destination,
boundaryResources: BoundaryState,
boundaryResources: BoundaryResources,
): void {
writeChunk(destination, arrayFirstOpenBracket);

Expand Down Expand Up @@ -5019,7 +5019,7 @@ export function createHoistableState(): HoistableState {
};
}

export type BoundaryState = {
export type BoundaryResources = {
// style dependencies
styles: Set<StyleQueue>,
stylesheets: Set<StylesheetResource>,
Expand All @@ -5032,7 +5032,7 @@ export type StyleQueue = {
sheets: Map<string, StylesheetResource>,
};

export function createBoundaryState(): BoundaryState {
export function createBoundaryResources(): BoundaryResources {
return {
styles: new Set(),
stylesheets: new Set(),
Expand Down Expand Up @@ -5638,35 +5638,35 @@ function adoptPreloadCredentials(
if (target.integrity == null) target.integrity = preloadState[1];
}

export function hoistHoistableState(
parentHoistableState: HoistableState,
hoistableState: HoistableState,
export function hoistHoistables(
target: HoistableState,
source: HoistableState,
) {
parentHoistableState.charset.push(...hoistableState.charset);
parentHoistableState.viewport.push(...hoistableState.viewport);
parentHoistableState.chunks.push(...hoistableState.chunks);
target.charset.push(...source.charset);
target.viewport.push(...source.viewport);
target.chunks.push(...source.chunks);
}

function hoistStyleQueueDependency(
this: BoundaryState,
this: BoundaryResources,
styleQueue: StyleQueue,
) {
this.styles.add(styleQueue);
}

function hoistStylesheetDependency(
this: BoundaryState,
this: BoundaryResources,
stylesheet: StylesheetResource,
) {
this.stylesheets.add(stylesheet);
}

export function hoistBoundaryState(
targetState: BoundaryState,
sourceState: BoundaryState,
export function hoistBoundaryResources(
target: BoundaryResources,
source: BoundaryResources,
): void {
sourceState.styles.forEach(hoistStyleQueueDependency, targetState);
sourceState.stylesheets.forEach(hoistStylesheetDependency, targetState);
source.styles.forEach(hoistStyleQueueDependency, target);
source.stylesheets.forEach(hoistStylesheetDependency, target);
}

export type TransitionStatus = FormStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export const doctypeChunk: PrecomputedChunk = stringToPrecomputedChunk('');

export type {
ResumableState,
BoundaryState,
HoistableState,
BoundaryResources,
FormatContext,
} from './ReactFizzConfigDOM';

Expand All @@ -136,13 +137,13 @@ export {
writeCompletedRoot,
createRootFormatContext,
createResumableState,
createBoundaryState,
createBoundaryResources,
createHoistableState,
writePreamble,
writeHoistables,
writePostamble,
hoistBoundaryState,
hoistHoistableState,
hoistBoundaryResources,
hoistHoistables,
prepareHostDispatcher,
} from './ReactFizzConfigDOM';

Expand Down
6 changes: 3 additions & 3 deletions packages/react-noop-renderer/src/ReactNoopServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ type Destination = {
};

type RenderState = null;
type BoundaryState = null;
type HoistableState = null;
type BoundaryResources = null;

const POP = Buffer.from('/', 'utf8');

Expand Down Expand Up @@ -263,15 +263,15 @@ const ReactNoopServer = ReactFizzServer({
writeHoistables() {},
writePostamble() {},

createBoundaryState(): BoundaryState {
createBoundaryResources(): BoundaryResources {
return null;
},

createHoistableState(): HoistableState {
return null;
},

hoistHoistableState(
hoistHoistables(
parentHoistableState: HoistableState,
hoistableState: HoistableState,
) {},
Expand Down
Loading

0 comments on commit 81d6691

Please sign in to comment.