Best JavaScript code snippet using playwright-internal
ReactFiberBeginWork.js
Source:ReactFiberBeginWork.js
...83 // Any deletions get added first into the effect list.84 workInProgress.firstEffect = workInProgress.progressedFirstDeletion;85 workInProgress.lastEffect = workInProgress.progressedLastDeletion;86 }87 function reconcileChildren(current, workInProgress, nextChildren) {88 const priorityLevel = workInProgress.pendingWorkPriority;89 reconcileChildrenAtPriority(current, workInProgress, nextChildren, priorityLevel);90 }91 function reconcileChildrenAtPriority(current, workInProgress, nextChildren, priorityLevel) {92 // At this point any memoization is no longer valid since we'll have changed93 // the children.94 workInProgress.memoizedProps = null;95 if (!current) {96 // If this is a fresh new component that hasn't been rendered yet, we97 // won't update its child set by applying minimal side-effects. Instead,98 // we will add them all to the child before it gets rendered. That means99 // we can optimize this reconciliation pass by not tracking side-effects.100 workInProgress.child = mountChildFibersInPlace(101 workInProgress,102 workInProgress.child,103 nextChildren,104 priorityLevel105 );106 } else if (current.child === workInProgress.child) {107 // If the current child is the same as the work in progress, it means that108 // we haven't yet started any work on these children. Therefore, we use109 // the clone algorithm to create a copy of all the current children.110 // If we had any progressed work already, that is invalid at this point so111 // let's throw it out.112 clearDeletions(workInProgress);113 workInProgress.child = reconcileChildFibers(114 workInProgress,115 workInProgress.child,116 nextChildren,117 priorityLevel118 );119 transferDeletions(workInProgress);120 } else {121 // If, on the other hand, it is already using a clone, that means we've122 // already begun some work on this tree and we can continue where we left123 // off by reconciling against the existing children.124 workInProgress.child = reconcileChildFibersInPlace(125 workInProgress,126 workInProgress.child,127 nextChildren,128 priorityLevel129 );130 transferDeletions(workInProgress);131 }132 markChildAsProgressed(current, workInProgress, priorityLevel);133 }134 function updateFragment(current, workInProgress) {135 var nextChildren = workInProgress.pendingProps;136 reconcileChildren(current, workInProgress, nextChildren);137 }138 function updateFunctionalComponent(current, workInProgress) {139 var fn = workInProgress.type;140 var props = workInProgress.pendingProps;141 var context = getMaskedContext(workInProgress);142 // TODO: Disable this before release, since it is not part of the public API143 // I use this for testing to compare the relative overhead of classes.144 if (typeof fn.shouldComponentUpdate === 'function') {145 if (workInProgress.memoizedProps !== null) {146 if (!fn.shouldComponentUpdate(workInProgress.memoizedProps, props)) {147 return bailoutOnAlreadyFinishedWork(current, workInProgress);148 }149 }150 }151 var nextChildren;152 if (__DEV__) {153 ReactCurrentOwner.current = workInProgress;154 nextChildren = fn(props, context);155 } else {156 nextChildren = fn(props, context);157 }158 reconcileChildren(current, workInProgress, nextChildren);159 return workInProgress.child;160 }161 function updateClassComponent(current : ?Fiber, workInProgress : Fiber) {162 let shouldUpdate;163 if (!current) {164 if (!workInProgress.stateNode) {165 // In the initial pass we might need to construct the instance.166 constructClassInstance(workInProgress);167 mountClassInstance(workInProgress);168 shouldUpdate = true;169 } else {170 // In a resume, we'll already have an instance we can reuse.171 shouldUpdate = resumeMountClassInstance(workInProgress);172 }173 } else {174 shouldUpdate = updateClassInstance(current, workInProgress);175 }176 if (!shouldUpdate) {177 return bailoutOnAlreadyFinishedWork(current, workInProgress);178 }179 // Rerender180 const instance = workInProgress.stateNode;181 ReactCurrentOwner.current = workInProgress;182 const nextChildren = instance.render();183 reconcileChildren(current, workInProgress, nextChildren);184 // Put context on the stack because we will work on children185 if (isContextProvider(workInProgress)) {186 pushContextProvider(workInProgress, true);187 }188 return workInProgress.child;189 }190 function updateHostComponent(current, workInProgress) {191 let nextChildren = workInProgress.pendingProps.children;192 if (typeof nextChildren === 'string' || typeof nextChildren === 'number') {193 // We special case a direct text child of a host node. This is a common194 // case. We won't handle it as a reified child. We will instead handle195 // this in the host environment that also have access to this prop. That196 // avoids allocating another HostText fiber and traversing it.197 nextChildren = null;198 }199 if (workInProgress.pendingProps.hidden &&200 workInProgress.pendingWorkPriority !== OffscreenPriority) {201 // If this host component is hidden, we can bail out on the children.202 // We'll rerender the children later at the lower priority.203 // It is unfortunate that we have to do the reconciliation of these204 // children already since that will add them to the tree even though205 // they are not actually done yet. If this is a large set it is also206 // confusing that this takes time to do right now instead of later.207 if (workInProgress.progressedPriority === OffscreenPriority) {208 // If we already made some progress on the offscreen priority before,209 // then we should continue from where we left off.210 workInProgress.child = workInProgress.progressedChild;211 }212 // Reconcile the children and stash them for later work.213 reconcileChildrenAtPriority(current, workInProgress, nextChildren, OffscreenPriority);214 workInProgress.child = current ? current.child : null;215 if (!current) {216 // If this doesn't have a current we won't track it for placement217 // effects. However, when we come back around to this we have already218 // inserted the parent which means that we'll infact need to make this a219 // placement.220 // TODO: There has to be a better solution to this problem.221 let child = workInProgress.progressedChild;222 while (child) {223 child.effectTag = Placement;224 child = child.sibling;225 }226 }227 // Abort and don't process children yet.228 return null;229 } else {230 reconcileChildren(current, workInProgress, nextChildren);231 return workInProgress.child;232 }233 }234 function mountIndeterminateComponent(current, workInProgress) {235 if (current) {236 throw new Error('An indeterminate component should never have mounted.');237 }238 var fn = workInProgress.type;239 var props = workInProgress.pendingProps;240 var context = getMaskedContext(workInProgress);241 var value;242 if (__DEV__) {243 ReactCurrentOwner.current = workInProgress;244 value = fn(props, context);245 } else {246 value = fn(props, context);247 }248 if (typeof value === 'object' && value && typeof value.render === 'function') {249 // Proceed under the assumption that this is a class instance250 workInProgress.tag = ClassComponent;251 adoptClassInstance(workInProgress, value);252 mountClassInstance(workInProgress);253 ReactCurrentOwner.current = workInProgress;254 value = value.render();255 } else {256 // Proceed under the assumption that this is a functional component257 workInProgress.tag = FunctionalComponent;258 }259 reconcileChildren(current, workInProgress, value);260 return workInProgress.child;261 }262 function updateCoroutineComponent(current, workInProgress) {263 var coroutine = (workInProgress.pendingProps : ?ReactCoroutine);264 if (!coroutine) {265 throw new Error('Should be resolved by now');266 }267 reconcileChildren(current, workInProgress, coroutine.children);268 }269 function updatePortalComponent(current, workInProgress) {270 const priorityLevel = workInProgress.pendingWorkPriority;271 const nextChildren = workInProgress.pendingProps;272 if (!current) {273 // Portals are special because we don't append the children during mount274 // but at commit. Therefore we need to track insertions which the normal275 // flow doesn't do during mount. This doesn't happen at the root because276 // the root always starts with a "current" with a null child.277 // TODO: Consider unifying this with how the root works.278 workInProgress.child = reconcileChildFibersInPlace(279 workInProgress,280 workInProgress.child,281 nextChildren,282 priorityLevel283 );284 markChildAsProgressed(current, workInProgress, priorityLevel);285 } else {286 reconcileChildren(current, workInProgress, nextChildren);287 }288 }289 /*290 function reuseChildrenEffects(returnFiber : Fiber, firstChild : Fiber) {291 let child = firstChild;292 do {293 // Ensure that the first and last effect of the parent corresponds294 // to the children's first and last effect.295 if (!returnFiber.firstEffect) {296 returnFiber.firstEffect = child.firstEffect;297 }298 if (child.lastEffect) {299 if (returnFiber.lastEffect) {300 returnFiber.lastEffect.nextEffect = child.firstEffect;301 }302 returnFiber.lastEffect = child.lastEffect;303 }304 } while (child = child.sibling);305 }306 */307 function bailoutOnAlreadyFinishedWork(current, workInProgress : Fiber) : ?Fiber {308 const priorityLevel = workInProgress.pendingWorkPriority;309 if (workInProgress.tag === HostComponent &&310 workInProgress.memoizedProps.hidden &&311 workInProgress.pendingWorkPriority !== OffscreenPriority) {312 // This subtree still has work, but it should be deprioritized so we need313 // to bail out and not do any work yet.314 // TODO: It would be better if this tree got its correct priority set315 // during scheduleUpdate instead because otherwise we'll start a higher316 // priority reconciliation first before we can get down here. However,317 // that is a bit tricky since workInProgress and current can have318 // different "hidden" settings.319 let child = workInProgress.progressedChild;320 while (child) {321 // To ensure that this subtree gets its priority reset, the children322 // need to be reset.323 child.pendingWorkPriority = OffscreenPriority;324 child = child.sibling;325 }326 return null;327 }328 // TODO: We should ideally be able to bail out early if the children have no329 // more work to do. However, since we don't have a separation of this330 // Fiber's priority and its children yet - we don't know without doing lots331 // of the same work we do anyway. Once we have that separation we can just332 // bail out here if the children has no more work at this priority level.333 // if (workInProgress.priorityOfChildren <= priorityLevel) {334 // // If there are side-effects in these children that have not yet been335 // // committed we need to ensure that they get properly transferred up.336 // if (current && current.child !== workInProgress.child) {337 // reuseChildrenEffects(workInProgress, child);338 // }339 // return null;340 // }341 if (current && workInProgress.child === current.child) {342 // If we had any progressed work already, that is invalid at this point so343 // let's throw it out.344 clearDeletions(workInProgress);345 }346 cloneChildFibers(current, workInProgress);347 markChildAsProgressed(current, workInProgress, priorityLevel);348 // Put context on the stack because we will work on children349 if (isContextProvider(workInProgress)) {350 pushContextProvider(workInProgress, false);351 }352 return workInProgress.child;353 }354 function bailoutOnLowPriority(current, workInProgress) {355 // TODO: What if this is currently in progress?356 // How can that happen? How is this not being cloned?357 return null;358 }359 function beginWork(current : ?Fiber, workInProgress : Fiber, priorityLevel : PriorityLevel) : ?Fiber {360 if (!workInProgress.return) {361 // Don't start new work with context on the stack.362 resetContext();363 }364 if (workInProgress.pendingWorkPriority === NoWork ||365 workInProgress.pendingWorkPriority > priorityLevel) {366 return bailoutOnLowPriority(current, workInProgress);367 }368 // If we don't bail out, we're going be recomputing our children so we need369 // to drop our effect list.370 workInProgress.firstEffect = null;371 workInProgress.lastEffect = null;372 if (workInProgress.progressedPriority === priorityLevel) {373 // If we have progressed work on this priority level already, we can374 // proceed this that as the child.375 workInProgress.child = workInProgress.progressedChild;376 }377 if ((workInProgress.pendingProps === null || (378 workInProgress.memoizedProps !== null &&379 workInProgress.pendingProps === workInProgress.memoizedProps380 )) &&381 workInProgress.updateQueue === null &&382 !hasContextChanged()) {383 return bailoutOnAlreadyFinishedWork(current, workInProgress);384 }385 switch (workInProgress.tag) {386 case IndeterminateComponent:387 return mountIndeterminateComponent(current, workInProgress);388 case FunctionalComponent:389 return updateFunctionalComponent(current, workInProgress);390 case ClassComponent:391 return updateClassComponent(current, workInProgress);392 case HostContainer: {393 const root = (workInProgress.stateNode : FiberRoot);394 if (root.pendingContext) {395 pushTopLevelContextObject(396 root.pendingContext,397 root.pendingContext !== root.context398 );399 } else {400 pushTopLevelContextObject(root.context, false);401 }402 reconcileChildren(current, workInProgress, workInProgress.pendingProps);403 // A yield component is just a placeholder, we can just run through the404 // next one immediately.405 return workInProgress.child;406 }407 case HostComponent:408 return updateHostComponent(current, workInProgress);409 case HostText:410 // Nothing to do here. This is terminal. We'll do the completion step411 // immediately after.412 return null;413 case CoroutineHandlerPhase:414 // This is a restart. Reset the tag to the initial phase.415 workInProgress.tag = CoroutineComponent;416 // Intentionally fall through since this is now the same....
ReactFiberFundamental-test.internal.js
Source:ReactFiberFundamental-test.internal.js
1/**2 * Copyright (c) Facebook, Inc. and its affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @emails react-core8 */9'use strict';10let React;11let ReactNoop;12let Scheduler;13let ReactFeatureFlags;14let ReactTestRenderer;15let ReactDOM;16let ReactDOMServer;17function createReactFundamentalComponent(fundamentalImpl) {18 return React.unstable_createFundamental(fundamentalImpl);19}20function init() {21 jest.resetModules();22 ReactFeatureFlags = require('shared/ReactFeatureFlags');23 ReactFeatureFlags.enableFundamentalAPI = true;24 React = require('react');25 Scheduler = require('scheduler');26}27function initNoopRenderer() {28 init();29 ReactNoop = require('react-noop-renderer');30}31function initTestRenderer() {32 init();33 ReactTestRenderer = require('react-test-renderer');34}35function initReactDOM() {36 init();37 ReactDOM = require('react-dom');38}39function initReactDOMServer() {40 init();41 ReactDOMServer = require('react-dom/server');42}43describe('ReactFiberFundamental', () => {44 describe('NoopRenderer', () => {45 beforeEach(() => {46 initNoopRenderer();47 });48 it('should render a simple fundamental component with a single child', () => {49 const FundamentalComponent = createReactFundamentalComponent({50 reconcileChildren: true,51 getInstance(context, props, state) {52 const instance = {53 children: [],54 text: null,55 type: 'test',56 };57 return instance;58 },59 });60 const Test = ({children}) => (61 <FundamentalComponent>{children}</FundamentalComponent>62 );63 ReactNoop.render(<Test>Hello world</Test>);64 expect(Scheduler).toFlushWithoutYielding();65 expect(ReactNoop).toMatchRenderedOutput(<test>Hello world</test>);66 ReactNoop.render(<Test>Hello world again</Test>);67 expect(Scheduler).toFlushWithoutYielding();68 expect(ReactNoop).toMatchRenderedOutput(<test>Hello world again</test>);69 ReactNoop.render(null);70 expect(Scheduler).toFlushWithoutYielding();71 expect(ReactNoop).toMatchRenderedOutput(null);72 });73 });74 describe('NoopTestRenderer', () => {75 beforeEach(() => {76 initTestRenderer();77 });78 it('should render a simple fundamental component with a single child', () => {79 const FundamentalComponent = createReactFundamentalComponent({80 reconcileChildren: true,81 getInstance(context, props, state) {82 const instance = {83 children: [],84 props,85 type: 'test',86 tag: 'INSTANCE',87 };88 return instance;89 },90 });91 const Test = ({children}) => (92 <FundamentalComponent>{children}</FundamentalComponent>93 );94 const root = ReactTestRenderer.create(null);95 root.update(<Test>Hello world</Test>);96 expect(Scheduler).toFlushWithoutYielding();97 expect(root).toMatchRenderedOutput(<test>Hello world</test>);98 root.update(<Test>Hello world again</Test>);99 expect(Scheduler).toFlushWithoutYielding();100 expect(root).toMatchRenderedOutput(<test>Hello world again</test>);101 root.update(null);102 expect(Scheduler).toFlushWithoutYielding();103 expect(root).toMatchRenderedOutput(null);104 });105 });106 describe('ReactDOM', () => {107 beforeEach(() => {108 initReactDOM();109 });110 it('should render a simple fundamental component with a single child', () => {111 const FundamentalComponent = createReactFundamentalComponent({112 reconcileChildren: true,113 getInstance(context, props, state) {114 const instance = document.createElement('div');115 return instance;116 },117 });118 const Test = ({children}) => (119 <FundamentalComponent>{children}</FundamentalComponent>120 );121 const container = document.createElement('div');122 ReactDOM.render(<Test>Hello world</Test>, container);123 expect(Scheduler).toFlushWithoutYielding();124 expect(container.innerHTML).toBe('<div>Hello world</div>');125 ReactDOM.render(<Test>Hello world again</Test>, container);126 expect(Scheduler).toFlushWithoutYielding();127 expect(container.innerHTML).toBe('<div>Hello world again</div>');128 ReactDOM.render(null, container);129 expect(Scheduler).toFlushWithoutYielding();130 expect(container.innerHTML).toBe('');131 });132 it('should render a simple fundamental component without reconcileChildren', () => {133 const FundamentalComponent = createReactFundamentalComponent({134 reconcileChildren: false,135 getInstance(context, props, state) {136 const instance = document.createElement('div');137 instance.textContent = 'Hello world';138 return instance;139 },140 });141 const Test = () => <FundamentalComponent />;142 const container = document.createElement('div');143 ReactDOM.render(<Test />, container);144 expect(Scheduler).toFlushWithoutYielding();145 expect(container.innerHTML).toBe('<div>Hello world</div>');146 // Children should be ignored147 ReactDOM.render(<Test>Hello world again</Test>, container);148 expect(Scheduler).toFlushWithoutYielding();149 expect(container.innerHTML).toBe('<div>Hello world</div>');150 ReactDOM.render(null, container);151 expect(Scheduler).toFlushWithoutYielding();152 expect(container.innerHTML).toBe('');153 });154 });155 describe('ReactDOMServer', () => {156 beforeEach(() => {157 initReactDOMServer();158 });159 it('should render a simple fundamental component with a single child', () => {160 const getInstance = jest.fn();161 const FundamentalComponent = createReactFundamentalComponent({162 reconcileChildren: true,163 getInstance,164 getServerSideString(context, props) {165 return `<div>`;166 },167 getServerSideStringClose(context, props) {168 return `</div>`;169 },170 });171 const Test = ({children}) => (172 <FundamentalComponent>{children}</FundamentalComponent>173 );174 expect(getInstance).not.toBeCalled();175 let output = ReactDOMServer.renderToString(<Test>Hello world</Test>);176 expect(output).toBe('<div>Hello world</div>');177 output = ReactDOMServer.renderToString(<Test>Hello world again</Test>);178 expect(output).toBe('<div>Hello world again</div>');179 });180 it('should render a simple fundamental component without reconcileChildren', () => {181 const FundamentalComponent = createReactFundamentalComponent({182 reconcileChildren: false,183 getServerSideString(context, props) {184 return `<div>Hello world</div>`;185 },186 });187 const Test = () => <FundamentalComponent />;188 let output = ReactDOMServer.renderToString(<Test />);189 expect(output).toBe('<div>Hello world</div>');190 // Children should be ignored191 output = ReactDOMServer.renderToString(<Test>Hello world again</Test>);192 expect(output).toBe('<div>Hello world</div>');193 });194 });...
react-dom.js
Source:react-dom.js
...47 // : updateFunctionComponent(vnode);48 // } else {49 // node = document.createDocumentFragment();50 // }51 // reconcileChildren(props.children, node);52 updateNode(node, props);53 return node;54}55// éåä¸åèç¹-old56// function reconcileChildren(children, node) {57// for (let i = 0; i < children.length; i++) {58// let child = children[i];59// // childæ¯vnodeï¼é£éè¦ævnode->çå®domèç¹ï¼ç¶åæå
¥ç¶èç¹nodeä¸60// render(child, node);61// }62// }63// åè°åèç¹64// 1. ç»workInProgressæ·»å ä¸ä¸ªchildèç¹ï¼å°±æ¯childrenç第ä¸ä¸ªåèç¹å½¢æçfiber65// 2. å½¢æfiberæ¶æï¼æchildrenéèç¹éåä¸ï¼å½¢æfiberé¾è¡¨ç¶66function reconcileChildren(workInProgress, children) {67 let prevSibling = null;68 for (let i = 0; i < children.length; i++) {69 let child = children[i];70 // ä»å¤©å
åå次渲æ71 let newFiber = {72 type: child.type,73 props: child.props,74 node: null,75 base: null,76 return: workInProgress,77 effectTag: PLACEMENT78 };79 if (i === 0) {80 workInProgress.child = newFiber;81 } else {82 prevSibling.sibling = newFiber;83 }84 prevSibling = newFiber;85 }86}87// æ·»å èç¹å±æ§88function updateNode(node, nextVal) {89 Object.keys(nextVal)90 .filter(k => k !== "children")91 .forEach(k => {92 node[k] = nextVal[k];93 });94}95function updateClassComponent(vnode) {96 // const {type, props} = vnode;97 // const cmp = new type(props);98 // const vvnode = cmp.render();99 // // è¿åçå®domèç¹100 // const node = createNode(vvnode);101 // return node;102}103function updateFunctionComponent(fiber) {104 const {type, props} = fiber;105 const children = [type(props)];106 reconcileChildren(fiber, children);107}108function updateHostComponent(fiber) {109 if (!fiber.node) {110 fiber.node = createNode(fiber);111 }112 const {children} = fiber.props;113 reconcileChildren(fiber, children);114 console.log("updateHostComponent", fiber); //sy-log115}116function performUnitOfWork(fiber) {117 // step1: æ§è¡æ´æ°å½åfiber118 // todo119 // sth120 const {type} = fiber;121 if (typeof type === "function") {122 type.isReactComponent123 ? updateClassComponent(fiber)124 : updateFunctionComponent(fiber);125 } else {126 // åçæ ç¾ç127 updateHostComponent(fiber);...
scheduler.js
Source:scheduler.js
...74}75// ä»»å¡åççåä½å³ä¸ºfiber76function performUnitOfWork(fiber) {77 if (typeof fiber.type === "object") {78 reconcileChildren(fiber, [fiber.type]);79 } else if (typeof fiber.type === "function") {80 if (fiber.type.toString().startsWith("class")) {81 reconcileChildren(fiber, [new fiber.type(fiber.props).render()]);82 } else {83 wipFiber = fiber;84 wipFiber.hooks = [];85 wipHookIndex = 0;86 reconcileChildren(fiber, [fiber.type(fiber.props)]);87 }88 } else {89 reconcileChildren(fiber, fiber.props.children);90 if (fiber.type && !fiber.dom) {91 fiber.dom = createDomNode(fiber);92 }93 }94 if (fiber.child) {95 return fiber.child;96 }97 let nextFiber = fiber;98 while (nextFiber) {99 if (nextFiber.sibling) {100 return nextFiber.sibling;101 }102 nextFiber = nextFiber.parent;103 }...
ReactFiberReconciler.js
Source:ReactFiberReconciler.js
...7 // æ´æ°å±æ§8 updateNode(wip.stateNode, {}, wip.props)9 }10 // éååèç¹11 reconcileChildren(wip, wip.props.children)12}13// æ´æ°å½æ°ç»ä»¶14export function updateFunctionComponent(wip) {15 renderWithHooks(wip)16 const { type, props } = wip17 const children = type(props)18 reconcileChildren(wip, children)19}20export function updateText(wip) {21 wip.stateNode = document.createTextNode(wip.props.children)22}23export function updateFragmentComponent(wip) {24 reconcileChildren(wip, wip.props.children)25}26export function updateClassComponent(wip) {27 const { type, props } = wip28 const instance = new type(props)29 const children = instance.render()30 reconcileChildren(wip, children)31}32function deleteChild(returnFiber, childToDelete) {33 const deletions = returnFiber.deletions34 if (deletions) {35 returnFiber.deletions.push(childToDelete)36 } else {37 returnFiber.deletions = [childToDelete]38 }39}40function reconcileChildren(wip, children) {41 if (isStringOrNumber(children)) {42 return43 }44 const newChildren = isArray(children) ? children : [children]45 let previousNewFiber = null // è®°å½ä¸ä¸æ¬¡çfiber46 let oldFiber = wip.alternate?.child47 for (let i = 0; i < newChildren.length; i++) {48 const newChild = newChildren[i]49 const newFiber = createFiber(newChild, wip)50 const same = sameNode(newFiber, oldFiber)51 if (same) {52 Object.assign(newFiber, {53 stateNode: oldFiber.stateNode,54 alternate: oldFiber,...
FiberWork.js
Source:FiberWork.js
1import diffFiberNode from './FiberDiff';2import { createDom } from '../cute-react-dom/Dom';3import { flatArray } from '../Utils';4function reconcileChildren(parentFiber, childrenFiber) {5 if (childrenFiber === null || childrenFiber === undefined) {6 return;7 }8 let children = Array.isArray(childrenFiber) ? childrenFiber : [childrenFiber];9 // æå¹³æ°ç»ï¼é对 props.children 为æ°ç»è¿ç§æ
åµ10 // <div>11 // <div></div>12 // {props.children}13 // </div>14 children = flatArray(children);15 let oldChildFiber = parentFiber.alternate && parentFiber.alternate.child;16 // ä¸é¢çæä½å°±æ¯æ¼æ¥ fiber é¾è¡¨17 let prevFiber = null;18 for (let i = 0; i < children.length || oldChildFiber !== null; i++) {19 const child = children[i];20 const newFiber = diffFiberNode(oldChildFiber, child, parentFiber);21 if (i === 0) {22 parentFiber.child = newFiber;23 } else {24 prevFiber.sibling = newFiber;25 }26 if (oldChildFiber) {27 oldChildFiber = oldChildFiber.sibling;28 }29 prevFiber = newFiber;30 }31}32function updateHostComponent(workInProgress) {33 if (!workInProgress.stateNode) {34 workInProgress.stateNode = createDom(workInProgress);35 }36 if (workInProgress.props) {37 reconcileChildren(workInProgress, workInProgress.props.children);38 }39}40let wipFiber = null;41let hookIndex = null;42function updateFunctionComponent(workInProgress) {43 wipFiber = workInProgress;44 hookIndex = 0;45 wipFiber.hooks = [];46 const { type, props } = workInProgress;47 const children = [type(props)];48 reconcileChildren(workInProgress, children);49}50function updateClassComponent(workInProgress) {51 const { type, props } = workInProgress;52 const instance = new type(props);53 const children = instance.render();54 reconcileChildren(workInProgress, children);55}56function getWorkInProgressFiber() {57 return wipFiber;58}59function getHookIndex() {60 return hookIndex;61}62function setHookIndex(index) {63 hookIndex = index;64}65export {66 updateHostComponent,67 updateFunctionComponent,68 updateClassComponent,...
reconciler.js
Source:reconciler.js
...3 value: true4});5exports.reconcileChildren = reconcileChildren;6var _shared = require("./shared");7function reconcileChildren(wipFiber, children) {8 let oldFiber = wipFiber.alternate && wipFiber.alternate.child;9 let previousSibling = null;10 let index = 0;11 while (index < children.length || oldFiber) {12 const child = children[index];13 let newFiber = null;14 const isSameType = oldFiber && child && child.type === oldFiber.type;15 if (isSameType) {16 newFiber = {17 type: child.type,18 props: child.props,19 dom: oldFiber.dom,20 parent: wipFiber,21 alternate: oldFiber,...
kreact-dom.js
Source:kreact-dom.js
...15}16function updateTextComponent(vNode) {17 return document.createTextNode(vNode);18}19function reconcileChildren(node, children) {20 if(children === void 0) {21 return;22 }23 const newChildren = Array.isArray(children) ? children : [children];24 for (let newChild of newChildren) {25 render(newChild, node);26 }27}28function crateNode(vNode) {29 let node;30 console.log(vNode);31 const { type, props={} } = vNode;32 if (typeof type === 'string') {33 node = updateHostComponent(vNode);34 } else {35 node = updateTextComponent(vNode);36 }37 reconcileChildren(node, props.children);38 return node;39}...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'google.png' });7 await browser.close();8})();
Using AI Code Generation
1const { chromium } = require('playwright');2const fs = require('fs');3const path = require('path');4(async () => {5 const browser = await chromium.launch({ headless: false });6 const context = await browser.newContext();7 const page = await context.newPage();8 const root = await page.$('html');9 const children = await root.$$('body');10 const childrenOfBody = await children[0].$$('div');11 const childrenOfDiv = await childrenOfBody[0].$$('form');12 const childrenOfForm = await childrenOfDiv[0].$$('div');13 const childrenOfDiv1 = await childrenOfForm[0].$$('div');14 const childrenOfDiv2 = await childrenOfDiv1[0].$$('div');15 const childrenOfDiv3 = await childrenOfDiv2[0].$$('div');16 const childrenOfDiv4 = await childrenOfDiv3[0].$$('a');17 const childrenOfA = await childrenOfDiv4[0].$$('span');18 const childrenOfSpan = await childrenOfA[0].$$('svg');19 const childrenOfSvg = await childrenOfSpan[0].$$('path');20 const childrenOfPath = await childrenOfSvg[0].$$('path');21 const childrenOfPath1 = await childrenOfPath[0].$$('path');22 const childrenOfPath2 = await childrenOfPath1[0].$$('path');23 const childrenOfPath3 = await childrenOfPath2[0].$$('
Using AI Code Generation
1const { reconcileChildren } = require('playwright/lib/server/dom.js');2const { parseSelector } = require('playwright/lib/server/selectorsParser.js');3const { parseFunction } = require('playwright/lib/server/frames.js');4const dom = new DOM();5const root = dom.createDocument();6const body = dom.createElement('body');7dom.appendChild(root, body);8const selector = parseSelector('css=body');9const selector2 = parseSelector('css=div');10const selector3 = parseSelector('css=span');11const selector4 = parseSelector('css=span');12const selector5 = parseSelector('css=div');13const selector6 = parseSelector('css=div');14const selector7 = parseSelector('css=span');15const selector8 = parseSelector('css=div');16const selector9 = parseSelector('css=div');17const selector10 = parseSelector('css=span');18const selector11 = parseSelector('css=span');19const selector12 = parseSelector('css=div');20const selector13 = parseSelector('css=span');21const selector14 = parseSelector('css=div');22const selector15 = parseSelector('css=div');23const selector16 = parseSelector('css=span');24const selector17 = parseSelector('css=div');25const selector18 = parseSelector('css=span');26const selector19 = parseSelector('css=span');27const selector20 = parseSelector('css=div');28const selector21 = parseSelector('css=div');29const selector22 = parseSelector('css=span');30const selector23 = parseSelector('css=div');31const selector24 = parseSelector('css=span');32const selector25 = parseSelector('css=span');33const selector26 = parseSelector('css=div');34const selector27 = parseSelector('css=div');35const selector28 = parseSelector('css=span');36const selector29 = parseSelector('css=div');37const selector30 = parseSelector('css=span');38const selector31 = parseSelector('css=span');39const selector32 = parseSelector('css=div');40const selector33 = parseSelector('css=div');41const selector34 = parseSelector('css=span');42const selector35 = parseSelector('css=div');43const selector36 = parseSelector('css=span');44const selector37 = parseSelector('css=span');45const selector38 = parseSelector('css=div');
Using AI Code Generation
1const { reconcileChildren } = require('playwright/lib/server/dom.js');2const { parse } = require('playwright/lib/server/common/parser.js');3const { parseHtml } = require('playwright/lib/server/common/html.js');4const { serializeNode } = require('playwright/lib/server/common/serializers.js');5const { parseFragment } = require('playwright/lib/server/common/parser.js');6const htmlString = '<div>hello</div>';7const html = parseHtml(htmlString);8const node = parseFragment(html, html.firstChild);9const oldNode = parseFragment(html, html.firstChild);10const result = reconcileChildren(node, oldNode);11console.log(serializeNode(result));12[MIT](LICENSE)
Using AI Code Generation
1const { Playwright } = require('playwright');2const playwright = new Playwright({3 drivers: { chromium: { version: 'latest' } },4});5const browser = await playwright.chromium.launch();6const context = await browser.newContext();7const page = await context.newPage();8const { Internal } = require('playwright/lib/server/dom');9const internal = new Internal(page);10const { ElementHandle } = require('playwright/lib/server/dom');11const { Frame } = require('playwright/lib/server/frame');12const { Page } = require('playwright/lib/server/page');13const { JSHandle } = require('playwright/lib/server/javascript');14const { serializeResult } = require('playwright/lib/server/serializers');15const { JSHandleChannel } = require('playwright/lib/channels');16const { ElementHandleChannel } = require('playwright/lib/channels');17const { FrameChannel } = require('playwright/lib/channels');18const { PageChannel } = require('playwright/lib/channels');19const { CDPSession } = require('playwright/lib/cjs/server/cdpsession');20const { CDPSessionChannel } = require('playwright/lib/channels');21const { Dialog } = require('playwright/lib/server/dialog');22const { DialogChannel } = require('playwright/lib/channels');23const { JSHandleDispatcher } = require('playwright/lib/server/dispatchers');24const { ElementHandleDispatcher } =25 require('playwright/lib/server/dispatchers');26const { FrameDispatcher } = require('playwright/lib/server/dispatchers');27const { PageDispatcher } = require('playwright/lib/server/dispatchers');28const { CDPSessionDispatcher } = require('playwright/lib/server/dispatchers');29const { DialogDispatcher } = require('playwright/lib/server/dispatchers');30const { JSHandleInitializer } = require('playwright/lib/server/initializers');31const { ElementHandleInitializer } =32 require('playwright/lib/server/initializers');33const { FrameInitializer } = require('playwright/lib/server/initializers');34const { PageInitializer } = require('playwright/lib/server/initializers');35const { CDPSessionInitializer } = require('playwright/lib/server/initializers');36const { DialogInitializer } = require('playwright/lib/server/initializers');37const { JSHandleOwner } = require('playwright/lib/server/owners');38const { Element
Using AI Code Generation
1const pwInternal = require('playwright/lib/server/playwright').Playwright._internal;2const { reconcileChildren } = pwInternal;3const { parseSelector } = require('playwright/lib/server/common/selectorParser');4const { parseModifiers } = require('playwright/lib/server/common/selectors');5const { parseScript } = require('playwright/lib/server/common/javascript');6const { toJSHandle } = require('playwright/lib/server/common/converters');7const { ElementHandle } = require('playwright/lib/server/dom');8const { createHandle } = require('playwright/lib/server/common/createHandle');9const { createJSHandle } = require('playwright/lib/server/common/createJSHandle');10const { createHandleScope } = require('playwright/lib/server/common/handleScope');11const { createChannelOwner } = require('playwright/lib/server/common/channelOwner');12const { createChannelOwnerFromParent } = require('playwright/lib/server/common/channelOwner');13const { createGuid } = require('playwright/lib/server/common/utils');14const { createWaitTask } = require('playwright/lib/server/common/waitTask');15const { createWaitForFunctionTask } = require('playwright/lib/server/common/waitForFunctionTask');16const { createWaitForNavigationTask } = require('playwright/lib/server/common/waitForNavigationTask');17const { createWaitForSelectorTask } = require('playwright/lib/server/common/waitForSelectorTask');18const { createWaitForEventTask } = require('playwright/lib/server/common/waitForEventTask');19const { createWaitForTimeoutTask } = require('playwright/lib/server/common/waitForTimeoutTask');20const { createWaitForLoadStateTask } = require('playwright/lib/server/common/waitForLoadStateTask');21const { createWaitForURLTask } = require('playwright/lib/server/common/waitForURLTask');22const { createWaitForFrameTask } = require('playwright/lib/server/common/waitForFrameTask');23const { createWaitForWorkerTask } = require('playwright/lib/server/common/waitForWorkerTask');24const { createWaitForRequestTask } = require('playwright/lib/server/common/waitForRequestTask');25const { createWaitForResponseTask } = require('playwright/lib/server/common/waitForResponseTask');26const { createWaitForFileChooserTask } = require('playwright/lib/server/common/waitForFileChooserTask');27const { createWaitForConsoleMessageTask } = require('playwright/lib/server
Using AI Code Generation
1const { PlaywrightInternal } = require('playwright/lib/server/playwright');2const { ElementHandle } = require('playwright/lib/server/dom');3const dummyElementHandle = new ElementHandle(null, null, null, null, null, null);4const dummyInternal = new PlaywrightInternal(null, null, null, null, null, null, null, null);5const dummyNode = {6 attributes: {7 }8};9const dummyNode2 = {10 attributes: {11 }12};13const dummyNode3 = {14 attributes: {15 }16};17const dummyNode4 = {18 attributes: {19 }20};21const dummyNode5 = {22 attributes: {23 }24};25const dummyNode6 = {26 attributes: {27 }28};29const dummyNode7 = {30 attributes: {31 }32};33const dummyNode8 = {34 attributes: {35 }36};37const dummyNode9 = {38 attributes: {39 }40};41const dummyNode10 = {42 attributes: {43 }44};45const dummyNode11 = {46 attributes: {47 }48};49const dummyNode12 = {50 attributes: {51 }52};53const dummyNode13 = {54 attributes: {
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!