-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.yml
20369 lines (18891 loc) · 734 KB
/
rss.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>xiaotiandada/blog Issues</title>
<link>http://example.com/</link>
<description>xiaotiandada/blog Issues</description>
<lastBuildDate>Wed, 29 Jun 2022 10:57:05 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>https://github.com/jpmonette/feed</generator>
<language>zh-CN</language>
<copyright>All rights reserved 2022, xiaotian</copyright>
<item>
<title><![CDATA[[NodeJS] TypeError: string.replaceAll is not a function]]></title>
<link>https://github.com/xiaotiandada/blog/issues/116</link>
<guid>https://github.com/xiaotiandada/blog/issues/116</guid>
<pubDate>Wed, 29 Jun 2022 04:19:50 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://yongjinkim.com/nodejstypeerror-string-replaceall-is-not-a-function-%E3%81%AE%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%B3%95/">https://yongjinkim.com/nodejstypeerror-string-replaceall-is-not-a-function-の解決方法/</a></li>
</ul>
<p><code>String.prototype.replaceAll()</code></p>
<p>错误环境</p>
<ol>
<li>Github Actions 14x 测试报错</li>
<li>vercel 14x 环境运行报错</li>
</ol>
<p>解决方案</p>
<ol>
<li>升级 v15+</li>
<li>替换为 replace</li>
</ol>
]]></description>
</item>
<item>
<title><![CDATA[Webpack]]></title>
<link>https://github.com/xiaotiandada/blog/issues/115</link>
<guid>https://github.com/xiaotiandada/blog/issues/115</guid>
<pubDate>Sat, 25 Jun 2022 09:56:37 GMT</pubDate>
<description><![CDATA[<p>Babel 7 不需要 ts-loader。从 Babel 7 开始,ts-loader 是不必要的,因为 Babel 7 支持 TypeScript</p>
<ul>
<li><a href="https://github.com/Microsoft/TypeScript-Babel-Starter">https://github.com/Microsoft/TypeScript-Babel-Starter</a></li>
<li><a href="https://stackoverflow.com/questions/38320220/how-to-setup-typescript-babel-webpack">https://stackoverflow.com/questions/38320220/how-to-setup-typescript-babel-webpack</a></li>
<li><a href="https://babeljs.io/docs/en/babel-preset-typescript">https://babeljs.io/docs/en/babel-preset-typescript</a></li>
<li><a href="https://devblogs.microsoft.com/typescript/typescript-and-babel-7/">https://devblogs.microsoft.com/typescript/typescript-and-babel-7/</a></li>
</ul>
]]></description>
</item>
<item>
<title><![CDATA[Jest]]></title>
<link>https://github.com/xiaotiandada/blog/issues/114</link>
<guid>https://github.com/xiaotiandada/blog/issues/114</guid>
<pubDate>Mon, 27 Jun 2022 15:29:45 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://jestjs.io/">https://jestjs.io/</a></li>
<li><a href="https://www.jianshu.com/p/c1b5676c1edd">https://www.jianshu.com/p/c1b5676c1edd</a></li>
</ul>
<h2>Next + TypeScript + Jest</h2>
<pre><code> /node_modules/parse-domain/build/main.js:3
export { parseDomain, ParseResultType, } from "./parse-domain.js";
^^^^^^
SyntaxError: Unexpected token 'export'
1 | import assert from 'assert'
> 2 | import { fromUrl, parseDomain, ParseResultType } from 'parse-domain'
| ^
3 | import { toUnicode } from 'punycode'
4 |
</code></pre>
<p>忽略转换模式, 不起作用,直接删除 node_modules 反而生效. 但是会变慢...</p>
<pre><code class="language-js"> transformIgnorePatterns: [
'!node_modules/',
// '/node_modules/',
],
</code></pre>
<p>新的解决方案, 忽略一些报错的包</p>
<pre><code class="language-js"> transformIgnorePatterns: [
'/node_modules/(?!parse-domain|is-ip|ip-regex|uuid)', // SyntaxError: Unexpected token 'export'
],
</code></pre>
<pre><code> ● Test suite failed to run
ReferenceError: TextEncoder is not defined
1 | import assert from 'assert'
> 2 | import { fromUrl, parseDomain, ParseResultType } from 'parse-domain'
| ^
3 | import { toUnicode } from 'punycode'
</code></pre>
<p>设置 <code>TextEncoder</code></p>
<ul>
<li><a href="https://github.com/inrupt/solid-client-authn-js/issues/1676#issuecomment-917016646">https://github.com/inrupt/solid-client-authn-js/issues/1676#issuecomment-917016646</a></li>
<li><a href="https://stackoverflow.com/questions/57712235/referenceerror-textencoder-is-not-defined-when-running-react-scripts-test/72734315#72734315">https://stackoverflow.com/questions/57712235/referenceerror-textencoder-is-not-defined-when-running-react-scripts-test/72734315#72734315</a></li>
<li><a href="https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149">https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149</a></li>
<li><a href="https://github.com/microsoft/accessibility-insights-web/pull/5421/commits/9ad4e618019298d82732d49d00aafb846fb6bac7#diff-c4f1d9c9d7b982f26536dbd6bf8c0804c1c0011fba8bc6df6e937363acfffa1f">https://github.com/microsoft/accessibility-insights-web/pull/5421/commits/9ad4e618019298d82732d49d00aafb846fb6bac7#diff-c4f1d9c9d7b982f26536dbd6bf8c0804c1c0011fba8bc6df6e937363acfffa1f</a></li>
<li><a href="https://blog.csdn.net/weixin_42429288/article/details/124590185">https://blog.csdn.net/weixin_42429288/article/details/124590185</a></li>
<li><a href="https://github.com/vercel/next.js/blob/canary/examples/with-jest/jest.config.js">https://github.com/vercel/next.js/blob/canary/examples/with-jest/jest.config.js</a></li>
<li><a href="https://github.com/vercel/next.js/blob/canary/examples/with-jest-babel/jest.config.js">https://github.com/vercel/next.js/blob/canary/examples/with-jest-babel/jest.config.js</a></li>
<li><a href="https://juejin.cn/post/6844903942023823367#heading-8">https://juejin.cn/post/6844903942023823367#heading-8</a></li>
</ul>
<pre><code class="language-js">// ...
setupFiles: [`<rootDir>/jest-shim.js`],
testEnvironment: 'jest-environment-jsdom',
// ...
</code></pre>
<pre><code class="language-js">import { TextDecoder, TextEncoder } from 'util'
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
</code></pre>
<h2>decorators-legacy</h2>
<ul>
<li><a href="https://stackoverflow.com/questions/52262084/syntax-error-support-for-the-experimental-syntax-decorators-legacy-isnt-cur">https://stackoverflow.com/questions/52262084/syntax-error-support-for-the-experimental-syntax-decorators-legacy-isnt-cur</a></li>
<li><a href="https://babeljs.io/docs/en/babel-plugin-proposal-decorators">https://babeljs.io/docs/en/babel-plugin-proposal-decorators</a></li>
</ul>
<pre><code>Support for the experimental syntax 'decorators-legacy' isn't currently enabled (23:3):
</code></pre>
<h2>Env</h2>
<ul>
<li><a href="https://blog.shinki.net/posts/nextjs-jest-environment-variable">https://blog.shinki.net/posts/nextjs-jest-environment-variable</a></li>
<li><a href="https://nextjs.org/docs/basic-features/environment-variables">https://nextjs.org/docs/basic-features/environment-variables</a></li>
</ul>
<pre><code class="language-js">import { loadEnvConfig } from '@next/env'
const projectDir = process.cwd()
loadEnvConfig(projectDir)
</code></pre>
<h2>baseUrl paths</h2>
<ul>
<li><a href="https://stackoverflow.com/questions/50171412/jest-typescript-absolute-paths-baseurl-gives-error-cannot-find-module">https://stackoverflow.com/questions/50171412/jest-typescript-absolute-paths-baseurl-gives-error-cannot-find-module</a></li>
<li><a href="https://jestjs.io/zh-Hans/docs/configuration#moduledirectories-arraystring">https://jestjs.io/zh-Hans/docs/configuration#moduledirectories-arraystring</a></li>
</ul>
<pre><code class="language-js"> moduleDirectories: ['<rootDir>/node_modules', '<rootDir>'],
</code></pre>
]]></description>
</item>
<item>
<title><![CDATA[Cross-Origin-Embedder-Policy]]></title>
<link>https://github.com/xiaotiandada/blog/issues/113</link>
<guid>https://github.com/xiaotiandada/blog/issues/113</guid>
<pubDate>Wed, 15 Jun 2022 13:52:08 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy">https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy</a></li>
<li><a href="https://developer.chrome.com/blog/coep-credentialless-origin-trial/">https://developer.chrome.com/blog/coep-credentialless-origin-trial/</a></li>
<li><a href="https://web.dev/coop-coep/?utm_source=devtools">https://web.dev/coop-coep/?utm_source=devtools</a></li>
<li><a href="https://github.com/WICG/credentiallessness">https://github.com/WICG/credentiallessness</a></li>
<li><a href="https://github.com/WICG/proposals/issues/31">https://github.com/WICG/proposals/issues/31</a></li>
<li><a href="https://web.dev/i18n/zh/why-coop-coep/">https://web.dev/i18n/zh/why-coop-coep/</a></li>
</ul>
<pre><code class="language-ts">Cross-Origin-Embedder-Policy: unsafe-none | require-corp
</code></pre>
<p>相关信息 #111</p>
<img width="748" alt="image" src="https://user-images.githubusercontent.com/24250627/173811159-804ede52-80fc-4519-af82-8270deb3b63f.png">
]]></description>
</item>
<item>
<title><![CDATA[Cross-Origin-Opener-Policy]]></title>
<link>https://github.com/xiaotiandada/blog/issues/112</link>
<guid>https://github.com/xiaotiandada/blog/issues/112</guid>
<pubDate>Mon, 13 Jun 2022 17:10:53 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy">https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy</a></li>
</ul>
<pre><code class="language-ts">[
{
key: 'Cross-Origin-Embedder-Policy',
value: 'require-corp',
},
{
key: 'Cross-Origin-Opener-Policy',
value: 'same-origin',
},
]
</code></pre>
<p>如果需要浏览器支持 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer">SharedArrayBuffer</a> 需要设置 header <code>same-origin</code></p>
<pre><code class="language-ts">Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
</code></pre>
<ul>
<li><a href="https://web.dev/why-coop-coep/?utm_source=devtools">https://web.dev/why-coop-coep/?utm_source=devtools</a></li>
<li><a href="https://developer.chrome.com/docs/extensions/mv3/cross-origin-isolation/">https://developer.chrome.com/docs/extensions/mv3/cross-origin-isolation/</a></li>
<li><a href="https://github.com/camillelamy/explainers/blob/main/anonymous_iframes.md">https://github.com/camillelamy/explainers/blob/main/anonymous_iframes.md</a></li>
<li><a href="https://developer.chrome.com/origintrials/#/register_trial/303992974847508481">https://developer.chrome.com/origintrials/#/register_trial/303992974847508481</a></li>
<li><a href="https://blog.agektmr.com/2021/11/cross-origin-isolation.html">https://blog.agektmr.com/2021/11/cross-origin-isolation.html</a></li>
<li><a href="https://first-party-test.glitch.me/">https://first-party-test.glitch.me/</a></li>
<li><a href="https://stackoverflow.com/questions/70535752/enable-sharedarraybuffer-on-localhost">https://stackoverflow.com/questions/70535752/enable-sharedarraybuffer-on-localhost</a></li>
</ul>
<p>相关信息 #111</p>
]]></description>
</item>
<item>
<title><![CDATA[Cross-Origin Resource Policy (CORP)]]></title>
<link>https://github.com/xiaotiandada/blog/issues/111</link>
<guid>https://github.com/xiaotiandada/blog/issues/111</guid>
<pubDate>Mon, 13 Jun 2022 17:10:58 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Cross-Origin_Resource_Policy_(CORP)">https://developer.mozilla.org/en-US/docs/Web/HTTP/Cross-Origin_Resource_Policy_(CORP)</a></li>
<li><a href="https://web.dev/coop-coep/?utm_source=devtools">https://web.dev/coop-coep/?utm_source=devtools</a></li>
<li><a href="https://web.dev/same-site-same-origin/?utm_source=devtools">https://web.dev/same-site-same-origin/?utm_source=devtools</a></li>
</ul>
<p>如果父级设置了 <code>Cross-Origin-Opener-Policy</code></p>
<pre><code class="language-ts">[
{
key: 'Cross-Origin-Embedder-Policy',
value: 'require-corp',
},
{
key: 'Cross-Origin-Opener-Policy',
value: 'same-origin',
},
]
</code></pre>
<p>引用外部链接会无法工作,比如说 s3 img 资源。需要设置 header</p>
<p>example: <code>cross-origin-resource-policy: cross-origin</code></p>
<p><img src="https://user-images.githubusercontent.com/24250627/172420995-8a5a81ea-007d-4c42-b09e-38a241014389.png" alt="image"></p>
<pre><code class="language-ts">Cross-Origin-Resource-Policy: same-site | same-origin | cross-origin
</code></pre>
<p>引入 iframe easyRPG player 也会被阻止</p>
<p><img src="https://user-images.githubusercontent.com/24250627/173024097-faef9f19-b027-4a7a-94b8-5c18a4446c85.png" alt="image"></p>
<p>还会出现 <code>cross-origin-embedder-policy</code> 警告</p>
<p><img src="https://user-images.githubusercontent.com/24250627/173173791-2c74eede-75c5-420a-a2e3-480889e41197.png" alt="image"></p>
<pre><code>Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Resource-Policy: cross-origin
</code></pre>
]]></description>
</item>
<item>
<title><![CDATA[FileReader API]]></title>
<link>https://github.com/xiaotiandada/blog/issues/110</link>
<guid>https://github.com/xiaotiandada/blog/issues/110</guid>
<pubDate>Wed, 29 Jun 2022 04:10:47 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader">https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader</a></li>
<li><a href="https://dev.to/j471n/preview-file-before-uploading-in-react-27kn">https://dev.to/j471n/preview-file-before-uploading-in-react-27kn</a></li>
</ul>
<hr>
<ul>
<li><a href="https://ant.design/components/upload-cn/">https://ant.design/components/upload-cn/</a></li>
</ul>
<pre><code class="language-tsx">const getBase64 = (img: RcFile, callback: (url: string) => void) => {
const reader = new FileReader();
reader.addEventListener('load', () => callback(reader.result as string));
reader.readAsDataURL(img);
};
</code></pre>
<p><a href="https://developer.mozilla.org/zh-CN/docs/Web/API/URL/createObjectURL">https://developer.mozilla.org/zh-CN/docs/Web/API/URL/createObjectURL</a> 也可以做图片预览</p>
]]></description>
</item>
<item>
<title><![CDATA[theme]]></title>
<link>https://github.com/xiaotiandada/blog/issues/109</link>
<guid>https://github.com/xiaotiandada/blog/issues/109</guid>
<pubDate>Thu, 16 Jun 2022 11:51:28 GMT</pubDate>
<description><![CDATA[<h3>Next.js</h3>
<ul>
<li><a href="https://github.com/xiaotiandada/next-theme">https://github.com/xiaotiandada/next-theme</a></li>
<li><a href="https://github.com/xiaotiandada/next-theme/blob/main/pages/_app.tsx">https://github.com/xiaotiandada/next-theme/blob/main/pages/_app.tsx</a></li>
</ul>
<p>如果需要 可以考虑用 cookie 传递服务端的主题,因为 next-themes 使用的是 localstore 存储
大部分情况 不需要
可供参考:<a href="https://github.com/xeoneux/next-dark-mode/blob/main/src/index.tsx">https://github.com/xeoneux/next-dark-mode/blob/main/src/index.tsx</a>
使用 cookies 不是一个好主意 <a href="https://github.com/pacocoursey/next-themes/issues/17">https://github.com/pacocoursey/next-themes/issues/17</a></p>
<p>使用 localstore 结合 MUI UI 库可能会有闪烁的情况,需要更能多的实践</p>
<h3>MUI</h3>
<pre><code class="language-ts">import { createTheme, ThemeOptions } from '@mui/material/styles'
// https://mui.com/material-ui/customization/default-theme/
// https://material.io/resources/color
const defaultTheme: ThemeOptions = {
typography: {
button: {
textTransform: 'none',
},
},
}
export const lightTheme = createTheme({
palette: {
mode: 'light',
primary: {
main: '#ff2449',
light: '#ff6675',
dark: '#c40022',
},
},
...defaultTheme,
})
export const darkTheme = createTheme({
palette: {
mode: 'dark',
primary: {
main: '#f93c5b',
light: '#ff7588',
dark: '#bf0032',
},
},
...defaultTheme,
})
</code></pre>
<h3>Disqus</h3>
<p>-<a href="https://stackoverflow.com/questions/65260505/disqus-iframe-transparency-wont-work-on-chrome-87">https://stackoverflow.com/questions/65260505/disqus-iframe-transparency-wont-work-on-chrome-87</a>
-<a href="https://github.com/w3c/csswg-drafts/issues/4772">https://github.com/w3c/csswg-drafts/issues/4772</a></p>
<h3>Algolia</h3>
<ul>
<li><a href="https://github.com/algolia/autocomplete/blob/next/packages/autocomplete-theme-classic/src/theme.scss#L107">https://github.com/algolia/autocomplete/blob/next/packages/autocomplete-theme-classic/src/theme.scss#L107</a></li>
<li><a href="https://dev.to/algolia/creating-an-omnibar-with-autocomplete-3jgh">https://dev.to/algolia/creating-an-omnibar-with-autocomplete-3jgh</a></li>
</ul>
]]></description>
</item>
<item>
<title><![CDATA[React Hook Form + MUI 构建表单]]></title>
<link>https://github.com/xiaotiandada/blog/issues/108</link>
<guid>https://github.com/xiaotiandada/blog/issues/108</guid>
<pubDate>Mon, 20 Jun 2022 16:00:00 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://react-hook-form.com/">https://react-hook-form.com/</a></li>
<li><a href="https://mui.com/zh/">https://mui.com/zh/</a></li>
<li><a href="https://codesandbox.io/u/bluebill1049">https://codesandbox.io/u/bluebill1049</a></li>
<li><a href="https://github.com/react-hook-form/react-hook-form/tree/master/examples">https://github.com/react-hook-form/react-hook-form/tree/master/examples</a></li>
</ul>
]]></description>
</item>
<item>
<title><![CDATA[seo]]></title>
<link>https://github.com/xiaotiandada/blog/issues/107</link>
<guid>https://github.com/xiaotiandada/blog/issues/107</guid>
<pubDate>Fri, 20 May 2022 03:33:29 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://search.google.com/search-console/about">https://search.google.com/search-console/about</a></li>
<li><a href="https://analytics.google.com/analytics/web/">https://analytics.google.com/analytics/web/</a></li>
<li><a href="https://ziyuan.baidu.com/linksubmit/url?sitename=">https://ziyuan.baidu.com/linksubmit/url?sitename=</a></li>
<li><a href="https://tongji.baidu.com/web/welcome/login">https://tongji.baidu.com/web/welcome/login</a></li>
<li><a href="https://github.com/w3itch-crafter/w3itch-frontend/issues/129">https://github.com/w3itch-crafter/w3itch-frontend/issues/129</a></li>
</ul>
<hr>
<ul>
<li><a href="https://zhuanlan.zhihu.com/p/150718629">google search console 终极教程</a></li>
<li><a href="https://ahrefs.com/blog/zh/robots-txt/">关于Robots.txt和SEO: 你所需要知道的一切</a></li>
<li><a href="https://github.com/iamvishnusankar/next-sitemap#building-sitemaps">https://github.com/iamvishnusankar/next-sitemap#building-sitemaps</a></li>
</ul>
<p>Next 使用 next-sitemap</p>
<h3>Server side index-sitemaps (getServerSideSitemapIndex)</h3>
<p>生成 sitemaps 索引,在大文件拆分应该可以用到</p>
<ul>
<li><a href="https://github.com/iamvishnusankar/next-sitemap#server-side-index-sitemaps-getserversidesitemapindex">https://github.com/iamvishnusankar/next-sitemap#server-side-index-sitemaps-getserversidesitemapindex</a></li>
</ul>
<pre><code class="language-tsx">// pages/server-sitemap-index.xml/index.tsx
import { getServerSideSitemapIndex } from 'next-sitemap'
import { GetServerSideProps } from 'next'
export const getServerSideProps: GetServerSideProps = async (ctx) => {
// Method to source urls from cms
// const urls = await fetch('https//example.com/api')
return getServerSideSitemapIndex(ctx, [
'https://example.com/path-1.xml',
'https://example.com/path-2.xml',
])
}
// Default export to prevent next.js errors
export default function SitemapIndex() {}
</code></pre>
<pre><code class="language-xml"><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/path-1.xml</loc>
</sitemap>
<sitemap>
</sitemapindex>
</code></pre>
<h3>server side sitemap (getServerSideSitemap)</h3>
<p>生成 sitemaps</p>
<ul>
<li><a href="https://github.com/iamvishnusankar/next-sitemap#server-side-sitemap-getserversidesitemap">https://github.com/iamvishnusankar/next-sitemap#server-side-sitemap-getserversidesitemap</a></li>
</ul>
<pre><code class="language-tsx">// pages/server-sitemap.xml/index.tsx
import { getServerSideSitemap } from 'next-sitemap'
import { GetServerSideProps } from 'next'
export const getServerSideProps: GetServerSideProps = async (ctx) => {
// Method to source urls from cms
// const urls = await fetch('https//example.com/api')
const fields = [
{
loc: 'https://example.com', // Absolute url
lastmod: new Date().toISOString(),
// changefreq
// priority
},
{
loc: 'https://example.com/dynamic-path-2', // Absolute url
lastmod: new Date().toISOString(),
// changefreq
// priority
},
]
return getServerSideSitemap(ctx, fields)
}
// Default export to prevent next.js errors
export default function Sitemap() {}
</code></pre>
<p><code>fields</code> TS is <code>ISitemapField[]</code></p>
<pre><code class="language-xml"><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://demo.io/game/65</loc>
<lastmod>2022-05-12T16:35:07.696Z</lastmod>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
</urlset>
</code></pre>
<h3>JSON-LD</h3>
<ul>
<li><a href="https://github.com/garmeeh/next-seo#json-ld">https://github.com/garmeeh/next-seo#json-ld</a></li>
<li><a href="https://search.google.com/test/rich-results">https://search.google.com/test/rich-results</a></li>
<li><a href="https://developers.google.com/search/docs/advanced/robots/robots_meta_tag?hl=zh-cn">https://developers.google.com/search/docs/advanced/robots/robots_meta_tag?hl=zh-cn</a></li>
</ul>
<img width="791" alt="image" src="https://user-images.githubusercontent.com/24250627/168475174-bc6729eb-1d65-4791-9f59-c16b5aba4c20.png">
]]></description>
</item>
<item>
<title><![CDATA[npm, yarn scripts 使用指南]]></title>
<link>https://github.com/xiaotiandada/blog/issues/106</link>
<guid>https://github.com/xiaotiandada/blog/issues/106</guid>
<pubDate>Wed, 29 Jun 2022 03:58:23 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://www.ruanyifeng.com/blog/2016/10/npm_scripts.html">npm scripts 使用指南</a></li>
<li><a href="https://yarnpkg.com/advanced/lifecycle-scripts">https://yarnpkg.com/advanced/lifecycle-scripts</a></li>
</ul>
]]></description>
</item>
<item>
<title><![CDATA[Yarn]]></title>
<link>https://github.com/xiaotiandada/blog/issues/105</link>
<guid>https://github.com/xiaotiandada/blog/issues/105</guid>
<pubDate>Sun, 29 May 2022 10:05:39 GMT</pubDate>
<description><![CDATA[<pre><code>➤ YN0000: └ Completed in 0s 488ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ ethereumjs-abi@https://github.com/ethereumjs/ethereumjs-abi.git#commit=ee3994657fa7a427238e6ba92a84d0b529bbcde0 ca
➤ YN0013: │ ethereumjs-abi@https://github.com/ethereumjs/ethereumjs-abi.git#commit=ee3994657fa7a427238e6ba92a84d0b529bbcde0 ca
➤ YN0018: │ ethereumjs-abi@https://github.com/ethereumjs/ethereumjs-abi.git#commit=ee3994657fa7a427238e6ba92a84d0b529bbcde0: The remote archive doesn't match the expected checksum
➤ YN0000: └ Completed in 6s 167ms
➤ YN0000: Failed with errors in 6s 661ms
</code></pre>
<ul>
<li><a href="https://yarnpkg.com/advanced/error-codes#yn0018---cache_checksum_mismatch">https://yarnpkg.com/advanced/error-codes#yn0018---cache_checksum_mismatch</a></li>
<li><a href="https://github.com/yarnpkg/berry/issues/1142#issuecomment-607272809">https://github.com/yarnpkg/berry/issues/1142#issuecomment-607272809</a></li>
</ul>
<pre><code>yarn cache clean --all
YARN_CHECKSUM_BEHAVIOR=update yarn
</code></pre>
<h3>Github Actions</h3>
<ul>
<li><a href="https://yarnpkg.com/cli/install">https://yarnpkg.com/cli/install</a></li>
<li><a href="https://classic.yarnpkg.com/lang/en/docs/cli/install/">https://classic.yarnpkg.com/lang/en/docs/cli/install/</a></li>
<li><a href="https://stackoverflow.com/questions/58482655/what-is-the-closest-to-npm-ci-in-yarn">https://stackoverflow.com/questions/58482655/what-is-the-closest-to-npm-ci-in-yarn</a></li>
<li><a href="https://yarnpkg.com/getting-started/migration#step-by-step">https://yarnpkg.com/getting-started/migration#step-by-step</a></li>
<li><a href="https://github.com/actions/setup-node/pull/495">https://github.com/actions/setup-node/pull/495</a></li>
<li><a href="https://stackoverflow.com/questions/52630404/how-to-install-packages-based-on-the-lock-file-with-yarn">https://stackoverflow.com/questions/52630404/how-to-install-packages-based-on-the-lock-file-with-yarn</a>
<code>YN0050: The --frozen-lockfile option is deprecated; use --immutable and/or --immutable-cache instead</code></li>
</ul>
<pre><code class="language-yml">steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '14'
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn test
</code></pre>
<pre><code class="language-yml"> - run: yarn install --immutable
</code></pre>
<h3>npm/yarn scripts 使用指南</h3>
<ul>
<li><a href="https://www.ruanyifeng.com/blog/2016/10/npm_scripts.html">npm scripts 使用指南</a></li>
<li><a href="https://yarnpkg.com/advanced/lifecycle-scripts">https://yarnpkg.com/advanced/lifecycle-scripts</a></li>
</ul>
]]></description>
</item>
<item>
<title><![CDATA[Animation case]]></title>
<link>https://github.com/xiaotiandada/blog/issues/104</link>
<guid>https://github.com/xiaotiandada/blog/issues/104</guid>
<pubDate>Thu, 28 Apr 2022 10:45:24 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://codesandbox.io/s/swap-swap-rotate-bieux9">swap swap-rotate</a></li>
<li><a href="https://codesandbox.io/s/logo-showcase-l9t8e7?file=/src/App.tsx">logo-showcase</a></li>
<li><a href="https://codesandbox.io/s/showcase-g9j1j2">showcase</a></li>
</ul>
]]></description>
</item>
<item>
<title><![CDATA[iPhoneX 安全区域]]></title>
<link>https://github.com/xiaotiandada/blog/issues/103</link>
<guid>https://github.com/xiaotiandada/blog/issues/103</guid>
<pubDate>Wed, 27 Apr 2022 09:01:33 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://segmentfault.com/a/1190000022191869">https://segmentfault.com/a/1190000022191869</a></li>
<li><a href="https://www.shouxicto.com/article/1558.html">https://www.shouxicto.com/article/1558.html</a></li>
<li><a href="https://www.zcool.com.cn/article/ZNTU1MTUy.html">https://www.zcool.com.cn/article/ZNTU1MTUy.html</a></li>
</ul>
<pre><code class="language-css">padding-bottom: constant(safe-area-inset-bottom); /*兼容 IOS<11.2*/
padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/
</code></pre>
<p>今天又写到了底部导航,顺带记录一下吧。</p>
]]></description>
</item>
<item>
<title><![CDATA[为什么a标签中使用img后的高度多了几个像素?]]></title>
<link>https://github.com/xiaotiandada/blog/issues/102</link>
<guid>https://github.com/xiaotiandada/blog/issues/102</guid>
<pubDate>Tue, 26 Apr 2022 12:13:46 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://www.zhihu.com/question/26821863">https://www.zhihu.com/question/26821863</a></li>
<li><a href="https://segmentfault.com/q/1010000008659208/a-1020000008659599">https://segmentfault.com/q/1010000008659208/a-1020000008659599</a></li>
<li><a href="https://codeantenna.com/a/kOggMTb8Y0">https://codeantenna.com/a/kOggMTb8Y0</a></li>
</ul>
<p>部分安卓机器 img 没有设置高度,会使用默认长度拉伸。</p>
]]></description>
</item>
<item>
<title><![CDATA[PixiJS]]></title>
<link>https://github.com/xiaotiandada/blog/issues/101</link>
<guid>https://github.com/xiaotiandada/blog/issues/101</guid>
<pubDate>Tue, 26 Apr 2022 05:10:19 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://pixijs.com/">https://pixijs.com/</a></li>
<li><a href="https://reactpixi.org/">https://reactpixi.org/</a></li>
</ul>
<p>一些 Graphics、Sprite,React-Spring 使用。拖动 点击 填充素材等 。</p>
<p>之前项目 SVG 绘制的由于 DOM 太多导致体验不太好。</p>
<p><a href="https://github.com/xiaotiandada/hexagon">https://github.com/xiaotiandada/hexagon</a></p>
]]></description>
</item>
<item>
<title><![CDATA[Next]]></title>
<link>https://github.com/xiaotiandada/blog/issues/100</link>
<guid>https://github.com/xiaotiandada/blog/issues/100</guid>
<pubDate>Fri, 24 Jun 2022 03:27:36 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://nextjs.org/learn/foundations/about-nextjs">https://nextjs.org/learn/foundations/about-nextjs</a></li>
</ul>
<h3>next/image</h3>
<ul>
<li><a href="https://nextjs.org/docs/messages/sharp-missing-in-production">https://nextjs.org/docs/messages/sharp-missing-in-production</a></li>
<li><a href="https://www.npmjs.com/package/sharp">https://www.npmjs.com/package/sharp</a></li>
<li><a href="https://www.npmjs.com/package/@squoosh/lib">https://www.npmjs.com/package/@squoosh/lib</a></li>
</ul>
<h3>SEO</h3>
<ul>
<li><a href="https://nextjs.org/learn/seo/introduction-to-seo">https://nextjs.org/learn/seo/introduction-to-seo</a> (TODO)</li>
<li><a href="https://github.com/garmeeh/next-seo">https://github.com/garmeeh/next-seo</a></li>
<li><a href="https://nextjs.org/docs/advanced-features/measuring-performance">https://nextjs.org/docs/advanced-features/measuring-performance</a></li>
</ul>
<p>next-seo images 参数是一个数组,大部分情况都是使用最后一张作为封面。如果需要特定图片作为封面可只设置一张。</p>
<ul>
<li><a href="https://github.com/xiaotiandada/blog/issues/107">https://github.com/xiaotiandada/blog/issues/107</a> seo 部分可以参考</li>
</ul>
<h3>PWA</h3>
<ul>
<li><a href="https://github.com/shadowwalker/next-pwa">https://github.com/shadowwalker/next-pwa</a></li>
<li><a href="https://lavas-project.github.io/pwa-book/chapter06/1-manifest-json.html">https://lavas-project.github.io/pwa-book/chapter06/1-manifest-json.html</a></li>
<li><a href="https://developer.mozilla.org/zh-CN/docs/Web/Progressive_web_apps/Add_to_home_screen">https://developer.mozilla.org/zh-CN/docs/Web/Progressive_web_apps/Add_to_home_screen</a></li>
</ul>
<blockquote>
<p>Tip: Put the viewport head meta tag into _app.js rather than in _document.js if you need it.</p>
</blockquote>
<ul>
<li><a href="https://github.com/shadowwalker/next-pwa/issues/99">https://github.com/shadowwalker/next-pwa/issues/99</a></li>
</ul>
<h3>Layout</h3>
<ul>
<li><a href="https://nextjs.org/docs/basic-features/layouts">https://nextjs.org/docs/basic-features/layouts</a></li>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/layout-component">https://github.com/vercel/next.js/tree/canary/examples/layout-component</a></li>
<li><a href="https://adamwathan.me/2019/10/17/persistent-layout-patterns-in-nextjs/">https://adamwathan.me/2019/10/17/persistent-layout-patterns-in-nextjs/</a></li>
</ul>
<h3>Vercel</h3>
<p>λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)</p>
<blockquote>
<p>Error: No more than 12 Serverless Functions can be added to a Deployment on the Hobby plan. Create a team (Pro plan) to deploy more. Learn More: <a href="https://vercel.link/function-count-limit">https://vercel.link/function-count-limit</a></p>
</blockquote>
<p><a href="https://cant-xt.vercel.app/docs/folder-structure/next">https://cant-xt.vercel.app/docs/folder-structure/next</a> 一些 serverless limit 规则</p>
<h3>Header</h3>
<h4>SharedArrayBuffer</h4>
<ul>
<li><a href="https://nextjs.org/docs/advanced-features/security-headers">https://nextjs.org/docs/advanced-features/security-headers</a></li>
</ul>
<p>嵌入 iframe 需要支持 <code>SharedArrayBuffer</code>, 父级需要定义 header. 一些相关记录</p>
<p>#111
#112
#113</p>
<pre><code class="language-js">[
{
key: 'Cross-Origin-Embedder-Policy',
value: 'require-corp',
},
{
key: 'Cross-Origin-Opener-Policy',
value: 'same-origin',
},
]
</code></pre>
<p>iframe 源也开启了会被拒绝链接</p>
<img width="1388" alt="image" src="https://user-images.githubusercontent.com/24250627/172151602-4adaaf23-49c2-410c-bb2e-43b887e68371.png">
<h3>页面</h3>
<img width="612" alt="image" src="https://user-images.githubusercontent.com/24250627/173767739-048b3ce2-7ae8-4f3e-8b98-72aa2beb9877.png">
<p>第一次进入页面会 <code>SSG</code> 渲染页面。但是只在 /game 页面下定义了 header 参数,故首页无参数。</p>
<pre><code>[.
{
source: '/game/:path*',
headers: COEPHeaders,
},
{
source: '/zh-CN/game/:path*',
headers: COEPHeaders,
}
]
</code></pre>
<ul>
<li>如果直接从 /game 路由下进入响应 header</li>
<li>如果从首页/其他页面 进入 /game 路由则不会响应 header</li>
<li>切换页面返回数据 应该是客户端渲染 <code>CSR</code> <a href="https://juejin.cn/post/6925308376976982029">https://juejin.cn/post/6925308376976982029</a>
<ul>
<li><code>/_next/static/chunks/pages/game/%5Bid%5D.js</code> <code>Content-Type: application/javascript; charset=UTF-8</code></li>
<li><code>/_next/data/development/en-US/game/177.json?id=177</code> <code>Content-Type: application/json</code></li>
</ul>
</li>
</ul>
<img width="611" alt="image" src="https://user-images.githubusercontent.com/24250627/173768975-0b53bf95-83bb-42ed-8abd-e4fd22eb3692.png">
<img width="716" alt="image" src="https://user-images.githubusercontent.com/24250627/173769773-b1ba3f05-62d4-4cd9-8e62-172d03ea17b4.png">
<img width="714" alt="image" src="https://user-images.githubusercontent.com/24250627/173769801-8ad794f0-45a6-4402-b233-494fc08886f9.png">
<h2>getStaticProps</h2>
<p><a href="https://nextjs.org/docs/api-reference/data-fetching/get-static-props">https://nextjs.org/docs/api-reference/data-fetching/get-static-props</a></p>
<p>getStaticProps context locale 参数,默认定义为 <code>locale?: string</code>。大概看了一下源码的定义</p>
<p><a href="https://github.com/vercel/next.js/blob/39302141b5ea3a1e9a55af906129a44675337cf9/packages/next/export/index.ts#L375">https://github.com/vercel/next.js/blob/39302141b5ea3a1e9a55af906129a44675337cf9/packages/next/export/index.ts#L375</a></p>
<pre><code class="language-ts">locales: i18n?.locales,
locale: i18n?.defaultLocale,
defaultLocale: i18n?.defaultLocale,
domainLocales: i18n?.domains,
</code></pre>
<p>猜测应该是这里处理的。因为我们定义了 i18n config,locale 使用了 <code>i18n?.defaultLocale</code> 配置。然后会根据 cookie 或 url 路径处理好当前语言环境。</p>
<p>可能返回 <code>en-US | zh-CN</code></p>
<p>可以修改类型消除错误 <code>...(await serverSideTranslations(ctx.locale as string, ['common'])),</code></p>
<h3>webassembly</h3>
<p><a href="https://github.com/vercel/next.js/issues/25852">https://github.com/vercel/next.js/issues/25852</a></p>
<h3>Jest</h3>
<ul>
<li><a href="https://github.com/xiaotiandada/blog/issues/114">https://github.com/xiaotiandada/blog/issues/114</a></li>
</ul>
]]></description>
</item>
<item>
<title><![CDATA[Nest]]></title>
<link>https://github.com/xiaotiandada/blog/issues/99</link>
<guid>https://github.com/xiaotiandada/blog/issues/99</guid>
<pubDate>Tue, 21 Jun 2022 10:36:53 GMT</pubDate>
<description><![CDATA[<h2>class-validator</h2>
<ul>
<li><a href="https://juejin.cn/post/7083505497021612068">class-validator 校验器的使用</a></li>
</ul>
<h2>ValidationPipe</h2>
<blockquote>
<p><a href="https://docs.nestjs.com/techniques/validation#stripping-properties">https://docs.nestjs.com/techniques/validation#stripping-properties</a>
<a href="http://static.kancloud.cn/juukee/nestjs/2675355">http://static.kancloud.cn/juukee/nestjs/2675355</a>
<a href="https://juejin.cn/post/7064595876680826910">https://juejin.cn/post/7064595876680826910</a></p>
</blockquote>
<h3>transform</h3>
<pre><code class="language-ts">app.useGlobalPipes(
new ValidationPipe({
transform: true,
}),
);
</code></pre>
<pre><code class="language-ts">@Get(':id')
findOne(@Param('id') id: number) {
console.log(typeof id === 'number'); // true
return 'This action returns a user';
}
</code></pre>
<p>id 会自动从 string 转换成 number</p>
<h3>whitelist</h3>
<pre><code class="language-ts">app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
}),
);
</code></pre>
<p>true 时,自动删除非白名单属性(在验证类中没有任何修饰符的属性)。</p>
<pre><code class="language-ts">// Bad
// 所有参数都将被过滤
export class CreateCatDto {
public name: string;
public age: number;
public breed: string;
}
// Good
import { IsNumber, IsString } from 'class-validator';
export class CreateCatDto {
@IsString()
public name: string;
@IsNumber()
public age: number;
@IsString()
public breed: string;
}
</code></pre>
<h3>typeorm</h3>
<pre><code class="language-bash"> "typeorm": "^0.3.6",
"typeorm": "0.2.45",
</code></pre>
<p>0.3.x 按照文档无法工作
0.2.x 按照文档正常工作</p>
<ul>
<li><a href="https://blog.csdn.net/qq_27868061/article/details/79315985">typeorm删除之remove与delete</a></li>
</ul>
]]></description>
</item>
<item>
<title><![CDATA[Keyboard API]]></title>
<link>https://github.com/xiaotiandada/blog/issues/98</link>
<guid>https://github.com/xiaotiandada/blog/issues/98</guid>
<pubDate>Mon, 11 Apr 2022 16:34:09 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/lock">https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/lock</a></li>
</ul>
]]></description>
</item>
<item>
<title><![CDATA[Fullscreen API]]></title>
<link>https://github.com/xiaotiandada/blog/issues/97</link>
<guid>https://github.com/xiaotiandada/blog/issues/97</guid>
<pubDate>Fri, 22 Apr 2022 11:18:18 GMT</pubDate>
<description><![CDATA[<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API">https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API</a></li>
<li><a href="https://github.com/rafgraph/fscreen/blob/main/src/fscreen.js">https://github.com/rafgraph/fscreen/blob/main/src/fscreen.js</a></li>
<li><a href="https://web.dev/native-hardware-fullscreen/#let-the-user-choose-when-to-go-fullscreen">https://web.dev/native-hardware-fullscreen/#let-the-user-choose-when-to-go-fullscreen</a></li>
</ul>
<p>全屏 IOS 不支持,可以通过 CSS Fixed + PWA 实现比较好的体验</p>
]]></description>
</item>
<item>
<title><![CDATA[React]]></title>
<link>https://github.com/xiaotiandada/blog/issues/96</link>
<guid>https://github.com/xiaotiandada/blog/issues/96</guid>
<pubDate>Wed, 29 Jun 2022 04:06:46 GMT</pubDate>
<description><![CDATA[<h2>useEffect 在组件挂载时运行两次(StrictMode,NODE_ENV=development)</h2>
<pre><code>...
在严格模式下使用 React 18,`useEffect() that should run only on the initial mount, runs twice!`
...
---
...
React 18 为严格模式引入了一个新的仅限开发的检查。每当第一次安装组件时,此新检查将自动卸载并重新安装每个组件,并在第二次安装时恢复先前的状态。
...
</code></pre>
<h3>Before this change</h3>
<pre><code>* React mounts the component.
* Layout effects are created.
* Effect effects are created.
</code></pre>
<h3>With Strict Mode in React 18</h3>
<pre><code>* React mounts the component.
* Layout effects are created.
* Effect effects are created.
* React simulates unmounting the component.
* Layout effects are destroyed.
* Effects are destroyed.
* React simulates mounting the component with the previous state.
* Layout effect setup code runs
* Effect setup code runs
</code></pre>
<p>-<a href="https://github.com/facebook/react/issues/24502">https://github.com/facebook/react/issues/24502</a>
-<a href="https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-strict-mode">https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-strict-mode</a>
-<a href="https://levelup.gitconnected.com/react-18-the-trickiness-of-useeffect-fadfa65fa4b4">https://levelup.gitconnected.com/react-18-the-trickiness-of-useeffect-fadfa65fa4b4</a>
-<a href="https://stackoverflow.com/questions/72238175/react-18-useeffect-is-getting-called-two-times-on-mount">https://stackoverflow.com/questions/72238175/react-18-useeffect-is-getting-called-two-times-on-mount</a></p>
<h2>源码</h2>
<p>介绍全新的 JSX 转换 v17.0 RC</p>
<p><a href="https://zh-hans.reactjs.org/blog/2020/08/10/react-v17-rc.html">https://zh-hans.reactjs.org/blog/2020/08/10/react-v17-rc.html</a>
<a href="https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html">https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html</a></p>
<p>旧的 JSX 转换将 JSX 转换为React.createElement(...)调用,
新的 JSX 转换不是将 JSX 转换为React.createElement,而是自动从 React 包中的这些新入口点导入特殊函数并调用它们。</p>
<pre><code class="language-tsx">// Inserted by a compiler (don't import it yourself!)
import {jsx as _jsx} from 'react/jsx-runtime';
function App() {
return _jsx('h1', { children: 'Hello world' });
}
</code></pre>
<pre><code class="language-tsx"><h1 id="title" key="title" style={{ width: 100 }} onClick={() => console.log('onClick')}>hello<span data="d">12313</span></h1>
</code></pre>
<pre><code class="language-js">"use strict";
/*#__PURE__*/
React.createElement("h1", {
id: "title",
key: "title",
style: {
width: 100
},
onClick: () => console.log('onClick')
}, "hello", /*#__PURE__*/React.createElement("span", {
data: "d"
}, "12313"));
</code></pre>
<ul>
<li><a href="https://astexplorer.net/">https://astexplorer.net/</a></li>
<li><a href="https://babeljs.io">https://babeljs.io</a></li>
</ul>
<pre><code class="language-js">export const REACT_ELEMENT_TYPE = Symbol.for("react.element");
import { REACT_ELEMENT_TYPE } from "./shared/ReactSymbols";
const RESERVED_PROPS = {
key: true,
ref: true,
__self: true,
__source: true,
};
/**
* Factory method to create a new React element. This no longer adheres to
* the class pattern, so do not use new to call it. Also, instanceof check
* will not work. Instead test $$typeof field against Symbol.for('react.element') to check
* if something is a React Element.
*
* @param {*} type
* @param {*} props
* @param {*} key
* @param {string|object} ref
* @param {*} owner
* @param {*} self A *temporary* helper to detect places where `this` is
* different from the `owner` when React.createElement is called, so that we
* can warn. We want to get rid of owner and replace string `ref`s with arrow
* functions, and as long as `this` and owner are the same, there will be no
* change in behavior.
* @param {*} source An annotation object (added by a transpiler or otherwise)
* indicating filename, line number, and/or other information.
* @internal
*/
const ReactElement = function (type, key, ref, self, source, owner, props) {
const element = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: REACT_ELEMENT_TYPE,
// Built-in properties that belong on the element
type: type,
key: key,
ref: ref,
props: props,
// Record the component responsible for creating this element.
_owner: owner,
_store: {},
_self: self,
_source: source,
};
return element;
};
export function createElement(type, config, children) {
// Reserved names are extracted
const props = {};
let key = null;
let ref = null;
let self = null;
let source = null;
if (config != null) {
key = "" + config.key;
self = config.__self === undefined ? null : config.__self;
source = config.__source === undefined ? null : config.__source;
// Remaining properties are added to a new props object
for (const proName in config) {
if (
Object.hasOwnProperty.call(config, proName) &&
!RESERVED_PROPS.hasOwnProperty(proName)
) {
props[proName] = config[proName];
}
}
}
// Children can be more than one argument, and those are transferred onto
// the newly allocated props object.
const childrenLength = arguments.length - 2;
if (childrenLength === 1) {
props.children = children;
} else if (childrenLength > 1) {
const childArray = Array(childrenLength);
for (let i = 0; i < childArray.length; i++) {
childArray[i] = arguments[i + 2];
}
props.children = childArray;
}
const _owner = null;
return ReactElement(type, key, ref, self, source, _owner, props);
}
</code></pre>
<pre><code class="language-js">const emptyObject = {};
/**
* Base class helpers for the updating state of a component.
*/
export function Component(props) {
this.props = props;
this.refs = emptyObject;
}
Component.prototype.isReactComponent = {};
</code></pre>
<pre><code class="language-jsx">class PureComponents extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
console.log("nextProps", nextProps, nextState);
return (
shallowEqual(nextProps, this.props) && shallowEqual(nextState, this.state)
);
}
}
function shallowEqual(object1, object2) {
if (object1 === object2) {
return true;
}
if (
typeof object1 !== "object" ||
object1 === null ||
object2 !== "object" ||
object2 === null
) {
return false;
}
const keys1 = Object.keys(object1);
const keys2 = Object.keys(object2);
if (keys1.length !== keys2.length) {
return false;
}
for (let i = 0; i < keys1.length; i++) {
if (
!hasOwnProperty.call(object2, keys1[i]) ||
object1[keys1[i]] !== object2[keys1[i]]
) {
return false;
}
}
return true;
}
</code></pre>
<h3>React16废弃了哪些生命周期?为什么?</h3>
<ul>
<li><a href="https://blog.csdn.net/weixin_43392489/article/details/121438376">https://blog.csdn.net/weixin_43392489/article/details/121438376</a></li>
</ul>
<p>React16废弃的生命周期有3个will:
componentWillMount
componentWillReceiveProps
componentWillUpdate</p>
<h2>v16.13.1</h2>
<h3>createElement</h3>
<pre><code class="language-tsx">import { REACT_ELEMENT_TYPE } from '../../shared/ReactSymbols';
const hasOwnProperty = Object.prototype.hasOwnProperty;
const RESERVED_PROPS = {
key: true,
ref: true,
__self: true,
__source: true,
};
/**
* Create and return a new ReactElement of the given type.
* See https://reactjs.org/docs/react-api.html#createelement
*/
export function createElement(type: any, config: any, children: any) {
/**
* propName -> 属性名称