@@ -221,6 +221,7 @@ export type Task = {
221
221
blockedSegment : Segment , // the segment we'll write to
222
222
abortSet : Set < Task > , // the abortable set that this task belongs to
223
223
keyPath : Root | KeyNode , // the path of all parent keys currently rendering
224
+ formatContext : FormatContext , // the format's specific context (e.g. HTML/SVG/MathML)
224
225
legacyContext : LegacyContext , // the current legacy context that this task is executing in
225
226
context : ContextSnapshot , // the current new context that this task is executing in
226
227
treeContext : TreeContext , // the current tree context that this task is executing in
@@ -245,7 +246,7 @@ type Segment = {
245
246
+ chunks : Array < Chunk | PrecomputedChunk > ,
246
247
+ children : Array < Segment > ,
247
248
// The context that this segment was created in.
248
- formatContext : FormatContext ,
249
+ parentFormatContext : FormatContext ,
249
250
// If this segment represents a fallback, this is the content that will replace that fallback.
250
251
+ boundary : null | SuspenseBoundary ,
251
252
// used to discern when text separator boundaries are needed
@@ -386,6 +387,7 @@ export function createRequest(
386
387
rootSegment ,
387
388
abortSet ,
388
389
null ,
390
+ rootFormatContext ,
389
391
emptyContextObject ,
390
392
rootContextSnapshot ,
391
393
emptyTreeContext ,
@@ -442,6 +444,7 @@ function createTask(
442
444
blockedSegment : Segment ,
443
445
abortSet : Set < Task > ,
444
446
keyPath : Root | KeyNode ,
447
+ formatContext : FormatContext ,
445
448
legacyContext : LegacyContext ,
446
449
context : ContextSnapshot ,
447
450
treeContext : TreeContext ,
@@ -459,6 +462,7 @@ function createTask(
459
462
blockedSegment,
460
463
abortSet,
461
464
keyPath,
465
+ formatContext,
462
466
legacyContext,
463
467
context,
464
468
treeContext,
@@ -475,7 +479,7 @@ function createPendingSegment(
475
479
request : Request ,
476
480
index : number ,
477
481
boundary : null | SuspenseBoundary ,
478
- formatContext : FormatContext ,
482
+ parentFormatContext : FormatContext ,
479
483
lastPushedText : boolean ,
480
484
textEmbedded : boolean ,
481
485
) : Segment {
@@ -486,7 +490,7 @@ function createPendingSegment(
486
490
parentFlushed : false ,
487
491
chunks : [ ] ,
488
492
children : [ ] ,
489
- formatContext ,
493
+ parentFormatContext ,
490
494
boundary,
491
495
lastPushedText,
492
496
textEmbedded,
@@ -635,7 +639,7 @@ function renderSuspenseBoundary(
635
639
request ,
636
640
insertionIndex ,
637
641
newBoundary ,
638
- parentSegment . formatContext ,
642
+ task . formatContext ,
639
643
// boundaries never require text embedding at their edges because comment nodes bound them
640
644
false ,
641
645
false ,
@@ -649,7 +653,7 @@ function renderSuspenseBoundary(
649
653
request ,
650
654
0 ,
651
655
null ,
652
- parentSegment . formatContext ,
656
+ task . formatContext ,
653
657
// boundaries never require text embedding at their edges because comment nodes bound them
654
658
false ,
655
659
false ,
@@ -739,6 +743,7 @@ function renderSuspenseBoundary(
739
743
boundarySegment ,
740
744
fallbackAbortSet ,
741
745
task . keyPath ,
746
+ task . formatContext ,
742
747
task . legacyContext ,
743
748
task . context ,
744
749
task . treeContext ,
@@ -785,20 +790,20 @@ function renderHostElement(
785
790
props ,
786
791
request . resumableState ,
787
792
request . renderState ,
788
- segment . formatContext ,
793
+ task . formatContext ,
789
794
segment . lastPushedText ,
790
795
) ;
791
796
segment . lastPushedText = false ;
792
- const prevContext = segment . formatContext ;
793
- segment . formatContext = getChildFormatContext ( prevContext , type , props ) ;
797
+ const prevContext = task . formatContext ;
798
+ task . formatContext = getChildFormatContext ( prevContext , type , props ) ;
794
799
795
800
// We use the non-destructive form because if something suspends, we still
796
801
// need to pop back up and finish this subtree of HTML.
797
802
renderNode ( request , task , children , 0 ) ;
798
803
799
804
// We expect that errors will fatal the whole task and that we don't need
800
805
// the correct context. Therefore this is not in a finally.
801
- segment . formatContext = prevContext ;
806
+ task . formatContext = prevContext ;
802
807
pushEndInstance (
803
808
segment . chunks ,
804
809
type ,
@@ -1740,7 +1745,7 @@ function injectPostponedHole(
1740
1745
request ,
1741
1746
insertionIndex ,
1742
1747
null ,
1743
- segment . formatContext ,
1748
+ task . formatContext ,
1744
1749
// Adopt the parent segment's leading text embed
1745
1750
segment . lastPushedText ,
1746
1751
// Assume we are text embedded at the trailing edge
@@ -1765,7 +1770,7 @@ function spawnNewSuspendedTask(
1765
1770
request ,
1766
1771
insertionIndex ,
1767
1772
null ,
1768
- segment . formatContext ,
1773
+ task . formatContext ,
1769
1774
// Adopt the parent segment's leading text embed
1770
1775
segment . lastPushedText ,
1771
1776
// Assume we are text embedded at the trailing edge
@@ -1782,6 +1787,7 @@ function spawnNewSuspendedTask(
1782
1787
newSegment ,
1783
1788
task . abortSet ,
1784
1789
task . keyPath ,
1790
+ task . formatContext ,
1785
1791
task . legacyContext ,
1786
1792
task . context ,
1787
1793
task . treeContext ,
@@ -1814,7 +1820,7 @@ function renderNode(
1814
1820
1815
1821
// Snapshot the current context in case something throws to interrupt the
1816
1822
// process.
1817
- const previousFormatContext = task . blockedSegment . formatContext ;
1823
+ const previousFormatContext = task . formatContext ;
1818
1824
const previousLegacyContext = task . legacyContext ;
1819
1825
const previousContext = task . context ;
1820
1826
const previousKeyPath = task . keyPath ;
@@ -1850,7 +1856,7 @@ function renderNode(
1850
1856
1851
1857
// Restore the context. We assume that this will be restored by the inner
1852
1858
// functions in case nothing throws so we don't use "finally" here.
1853
- task . blockedSegment . formatContext = previousFormatContext ;
1859
+ task . formatContext = previousFormatContext ;
1854
1860
task . legacyContext = previousLegacyContext ;
1855
1861
task . context = previousContext ;
1856
1862
task . keyPath = previousKeyPath ;
@@ -1882,7 +1888,7 @@ function renderNode(
1882
1888
1883
1889
// Restore the context. We assume that this will be restored by the inner
1884
1890
// functions in case nothing throws so we don't use "finally" here.
1885
- task . blockedSegment . formatContext = previousFormatContext ;
1891
+ task . formatContext = previousFormatContext ;
1886
1892
task . legacyContext = previousLegacyContext ;
1887
1893
task . context = previousContext ;
1888
1894
task . keyPath = previousKeyPath ;
@@ -1896,7 +1902,7 @@ function renderNode(
1896
1902
}
1897
1903
// Restore the context. We assume that this will be restored by the inner
1898
1904
// functions in case nothing throws so we don't use "finally" here.
1899
- task . blockedSegment . formatContext = previousFormatContext ;
1905
+ task . formatContext = previousFormatContext ;
1900
1906
task . legacyContext = previousLegacyContext ;
1901
1907
task . context = previousContext ;
1902
1908
task . keyPath = previousKeyPath ;
@@ -2474,11 +2480,11 @@ function flushSegmentContainer(
2474
2480
writeStartSegment (
2475
2481
destination ,
2476
2482
request . renderState ,
2477
- segment . formatContext ,
2483
+ segment . parentFormatContext ,
2478
2484
segment . id ,
2479
2485
) ;
2480
2486
flushSegment ( request , destination , segment ) ;
2481
- return writeEndSegment ( destination , segment . formatContext ) ;
2487
+ return writeEndSegment ( destination , segment . parentFormatContext ) ;
2482
2488
}
2483
2489
2484
2490
function flushCompletedBoundary (
0 commit comments