Skip to content

Retain DOM nodes during streaming SSR updates #48258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8cdc622
Start on a test project for Web.JS
SteveSandersonMS May 16, 2023
a9ae397
Regenerate yarn lockfile
SteveSandersonMS May 16, 2023
b4d74c5
Begin implementing EditDistance
SteveSandersonMS May 16, 2023
94ba992
Try disabling workspaces because of CI issue
SteveSandersonMS May 16, 2023
ea5f6e1
Try to make the tests run in CI
SteveSandersonMS May 16, 2023
db8fc65
Report jest results to AzDO
SteveSandersonMS May 16, 2023
cc0ae15
Remove ComparisonResult
SteveSandersonMS May 17, 2023
db422e6
Instead of tracking equality results, track operations
SteveSandersonMS May 17, 2023
edf3ee6
Clean up
SteveSandersonMS May 17, 2023
5f82bca
Generalize to ItemList<T>
SteveSandersonMS May 17, 2023
cc818a8
Optimizations for edit distance
SteveSandersonMS May 17, 2023
82720db
Bring back ComparisonResult
SteveSandersonMS May 17, 2023
587ed3e
Support 'update' operation
SteveSandersonMS May 17, 2023
0e0e4db
Renames
SteveSandersonMS May 17, 2023
638af7a
Clean up
SteveSandersonMS May 17, 2023
da1af53
Optimize EditDistance results to skip returning Keep for common prefi…
SteveSandersonMS Jun 8, 2023
f54984d
Tidy
SteveSandersonMS Jun 8, 2023
f0953a0
Starting to implement the actual DOM updates. Currently only supports…
SteveSandersonMS Jun 8, 2023
1899f45
Handle insert
SteveSandersonMS Jun 8, 2023
e17416e
Deal with text nodes and comments
SteveSandersonMS Jun 8, 2023
5aa0a64
Renames for clarity
SteveSandersonMS Jun 8, 2023
caa2e9b
Rephrasings for clarity
SteveSandersonMS Jun 8, 2023
527c8a7
Basic element handling
SteveSandersonMS Jun 9, 2023
1a42d36
Better tests
SteveSandersonMS Jun 9, 2023
67f02a9
Updates attributes
SteveSandersonMS Jun 9, 2023
f8969c0
Insert attributes
SteveSandersonMS Jun 9, 2023
465c4bc
Delete attributes, albeit with a messy implementation
SteveSandersonMS Jun 9, 2023
9103d66
Update DomSync.test.ts
SteveSandersonMS Jun 9, 2023
676b110
Tidy up attribute handling
SteveSandersonMS Jun 9, 2023
481c8a1
Notes on @key
SteveSandersonMS Jun 12, 2023
4c1e6e9
Recurse into elements
SteveSandersonMS Jun 12, 2023
ae27a63
Use new DOM sync algorithm for streaming SSR
SteveSandersonMS Jun 13, 2023
3070ca0
Test to show how form values are handled
SteveSandersonMS Jun 13, 2023
99c5ae0
E2E test
SteveSandersonMS Jun 13, 2023
a142214
Update JS built files
SteveSandersonMS Jun 13, 2023
fc22a70
See it if builds in CI now without this workaround
SteveSandersonMS Jun 13, 2023
4f3c057
Revert "See it if builds in CI now without this workaround"
SteveSandersonMS Jun 13, 2023
239e16e
Refactoring so the attribute setting logic can be shared
SteveSandersonMS Jun 20, 2023
435fc83
Add some failing test cases
SteveSandersonMS Jun 20, 2023
574b4b0
Update the refactoring to better represent the different requirements
SteveSandersonMS Jun 20, 2023
b8ebca1
DomSync input element handling
SteveSandersonMS Jun 20, 2023
ef4d392
Update JS files
SteveSandersonMS Jun 20, 2023
e223cde
Allow disabling DOM preservation
SteveSandersonMS Jun 20, 2023
a6ef0ff
Update .js file
SteveSandersonMS Jun 20, 2023
fbf3de2
Tiny optimization
SteveSandersonMS Jun 20, 2023
b26b9e6
Update .js
SteveSandersonMS Jun 20, 2023
ddde8f2
Make it work with deferred values
SteveSandersonMS Jun 20, 2023
f45da57
Update .js
SteveSandersonMS Jun 20, 2023
01a94cd
Fix bug I just introduced
SteveSandersonMS Jun 20, 2023
63a7e12
Update .js
SteveSandersonMS Jun 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Components/Web.JS/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspaces-experimental false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately yes. Without it, it fails in CI due to a yarn restore issue related to Jest and its TypeScript integration.

Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<Project DefaultTargets="Build">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.props))\Directory.Build.props" />

<PropertyGroup>
<IsPackable>false</IsPackable>
<InstallArgs>--check-files</InstallArgs>
</PropertyGroup>

<PropertyGroup>
<IsUnitTestProject>true</IsUnitTestProject>
<TestDependsOnAspNetRuntime>false</TestDependsOnAspNetRuntime>

<!-- Npm tests don't run on Helix currently, so we need to set this to false to still run the tests on non-Helix -->
<BuildHelixPayload>false</BuildHelixPayload>
</PropertyGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.props))\Directory.Build.props" />

<ItemGroup>
<!--
Ensure files dependent projects expect exist and are up-to-date. Batching in Npm.Common.targets might skip
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.web.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.webview.js

Large diffs are not rendered by default.

201 changes: 201 additions & 0 deletions src/Components/Web.JS/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

module.exports = {
// All imported modules in your tests should be mocked automatically
// automock: false,

// Stop running tests after `n` failures
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "C:\\Users\\stevesa\\AppData\\Local\\Temp\\jest",

// Automatically clear mock calls, instances, contexts and results before every test
// clearMocks: false,

// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
// coverageDirectory: undefined,

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],

// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: false,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
// preset: undefined,

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
reporters: [
"default",
["./node_modules/jest-junit/index.js", { "outputDirectory": "../../../artifacts/log/", "outputName": `${process.platform}` + ".components-webjs.junit.xml" }]
],

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing
testEnvironment: "jsdom",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},

// Adds a location field to test results
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.tsx?$': ['@swc/jest'],
'^.+\\.jsx?$': ['@swc/jest'],
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "\\\\node_modules\\\\",
// "\\.pnp\\.[^\\\\]+$"
// ],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,
};
9 changes: 9 additions & 0 deletions src/Components/Web.JS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,32 @@
"clean": "node node_modules/rimraf/bin.js ./dist/Debug ./dist/Release",
"prebuild": "yarn run clean && yarn install --mutex network --frozen-lockfile || yarn install --mutex network --frozen-lockfile",
"lint": "eslint -c ./src/.eslintrc.js --ext .ts ./src",
"test": "jest",
"test:watch": "jest --watch",
"test:debug": "node --nolazy --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --colors --verbose",
"build": "yarn run build:debug && yarn run build:production",
"build:debug": "cd src && node ../node_modules/webpack-cli/bin/cli.js --mode development --config ./webpack.config.js",
"build:production": "cd src && node ../node_modules/webpack-cli/bin/cli.js --mode production --config ./webpack.config.js"
},
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.8",
"@jest/globals": "^29.5.0",
"@microsoft/dotnet-js-interop": "link:../../JSInterop/Microsoft.JSInterop.JS/src",
"@microsoft/signalr": "link:../../SignalR/clients/ts/signalr",
"@microsoft/signalr-protocol-msgpack": "link:../../SignalR/clients/ts/signalr-protocol-msgpack",
"@swc/core": "^1.3.58",
"@swc/jest": "^0.2.26",
"@types/dotnet": "./@types/dotnet",
"@types/jsdom": "^16.2.14",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"eslint": "^8.16.0",
"eslint-plugin-header": "^3.1.1",
"inspectpack": "^4.7.1",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-junit": "^16.0.0",
"rimraf": "^3.0.2",
"terser": "^5.14.2",
"ts-loader": "^9.2.6",
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Web.JS/src/Boot.Web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function boot(options?: Partial<WebStartOptions>): Promise<void> {
started = true;
await activateInteractiveComponents(options);

attachStreamingRenderingListener();
attachStreamingRenderingListener(options?.ssr);
}

async function activateInteractiveComponents(options?: Partial<WebStartOptions>) {
Expand Down
10 changes: 10 additions & 0 deletions src/Components/Web.JS/src/Platform/SsrStartOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

export interface SsrStartOptions {
/**
* If true, does not attempt to preserve DOM nodes when performing dynamic updates to SSR content
* (for example, during enhanced navigation or streaming rendering).
*/
disableDomPreservation?: boolean;
}
2 changes: 2 additions & 0 deletions src/Components/Web.JS/src/Platform/WebStartOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

import { WebAssemblyStartOptions } from './WebAssemblyStartOptions';
import { CircuitStartOptions } from './Circuits/CircuitStartOptions';
import { SsrStartOptions } from './SsrStartOptions';

export interface WebStartOptions {
circuit: CircuitStartOptions;
webAssembly: WebAssemblyStartOptions;
ssr: SsrStartOptions;
}
Loading