Skip to content
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

React 18 #6902

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b6c50ae
Update babel dependencies and configuration
steve9164 May 28, 2023
5c17326
Upgrade React to v18
steve9164 May 28, 2023
68b9c7e
Convert type assertions to "as" syntax
steve9164 May 28, 2023
7ed527a
Convert some type assertions that failed jscodeshift
steve9164 May 28, 2023
6f9a936
Convert type assertions to "as" syntax in tests
steve9164 May 28, 2023
25ca4f2
Update yarn lockfile
steve9164 May 28, 2023
1f5f618
Typescript fixes
steve9164 Sep 22, 2023
3d062f9
Run react-codemod update-react-imports
steve9164 Sep 22, 2023
ed09de2
Fix collision on global declaration between @types/dompurify dependen…
steve9164 Sep 22, 2023
04a3d1b
Fix other Typescript problems
steve9164 Sep 22, 2023
8d40587
Ensure that typescript is looking for types in node_modules
steve9164 Sep 22, 2023
ced3cf1
Extend tsconfig-node from default tsconfig so that typeRoots (and oth…
steve9164 Sep 22, 2023
ec350bb
Revert before merging; use react-18 TerriaMap branch
steve9164 Sep 27, 2023
c59eeb0
Fix eslint for React 17 and remove some instances of using unknown pr…
steve9164 Sep 27, 2023
17b873c
Remove some console logs from tests
steve9164 Sep 27, 2023
50e8575
Upgrade testing packages
steve9164 Sep 28, 2023
b3fa111
Allow rendering DragWrapper without DOM in test environment
steve9164 Sep 28, 2023
fc628b3
The ReactNode type already includes arrays, so make it also support s…
steve9164 Sep 28, 2023
70806c5
Ensure consistency when panel mounts before terria.pickedFeatures cha…
steve9164 Sep 28, 2023
d9b561e
Fix tests
steve9164 Sep 28, 2023
aa5a8bc
Update yarn lockfile
steve9164 Sep 28, 2023
1908915
Pass lint
steve9164 Sep 28, 2023
a86852a
Switch tests from release build to dev build
steve9164 Sep 28, 2023
e7f1706
Remove dodgy test
steve9164 Sep 28, 2023
d63f001
Use proper syled components, and add simple render regression tests
steve9164 Oct 13, 2023
ca90f20
Merge remote-tracking branch 'origin/main' into react18-sd
steve9164 Oct 16, 2023
f06d278
Remove React import
steve9164 Oct 16, 2023
2452ce4
Add typescript out directory to ignore files
steve9164 Oct 17, 2023
0cb7446
Type errors have fixed themselves?
steve9164 Oct 17, 2023
a0accef
Remove ViewState from component that doesn't use it
steve9164 Oct 30, 2023
629e0db
Merge remote-tracking branch 'origin/main' into react18-sd
steve9164 Nov 2, 2023
5d92e92
Remove uses of import * as React and uses of React.FC
steve9164 Nov 15, 2023
e6d5549
Update terriajs-server gulp task
steve9164 Nov 15, 2023
68d7d65
Organise imports
steve9164 Nov 15, 2023
b3f42ff
Fix React import for React 18
steve9164 Nov 15, 2023
9c2fb34
Wrap in ViewState context
steve9164 Nov 15, 2023
b41eb61
Upgrade mobx-react and update MomentPointsChart
steve9164 Nov 22, 2023
b3c8160
Convert Chart files from jsx + mobx to React functional tsx
steve9164 Dec 1, 2023
cee9235
Remove unnecessary condition and match conditionals
steve9164 Dec 3, 2023
d497b3e
Add function name
steve9164 Dec 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"useBuiltIns": "usage"
}
],
"@babel/preset-react",
["@babel/preset-react", { "runtime": "automatic" }],
["@babel/typescript", { "allowNamespaces": true }]
],
"plugins": [
Expand Down
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:jsx-control-statements/recommended"
],
"parser": "@babel/eslint-parser",
Expand Down Expand Up @@ -32,6 +33,9 @@
"jsx-control-statements/jsx-use-if-tag": 0,
"react/jsx-no-undef": 0,

/* Ignore styled-components css property */
"react/no-unknown-property": ["error", { "ignore": ["css"] }],

/*Possible Errors */
"no-cond-assign": [1, "except-parens"],
"no-console": 0,
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ jobs:
run: yarn prettier-check

- name: Build TerriaJS tests
run: yarn gulp lint release -- --continue
id: lint_build_spec
run: yarn gulp lint build -- --continue
env:
NODE_OPTIONS: --max_old_space_size=4096

# Run on failure of gulp lint build, in case it's a lint failure
- name: Run tests using xvfb
uses: GabrielBB/xvfb-action@v1
if: ${{success() || steps.lint_build_spec.outcome == 'failure'}}
with:
run: yarn gulp test-firefox
2 changes: 1 addition & 1 deletion buildprocess/ci-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm install -g yarn@^1.19.0

# Clone and build TerriaMap, using this version of TerriaJS
TERRIAJS_COMMIT_HASH=$(git rev-parse HEAD)
git clone -b main https://github.com/TerriaJS/TerriaMap.git
git clone -b react-18 https://github.com/TerriaJS/TerriaMap.git
cd TerriaMap
TERRIAMAP_COMMIT_HASH=$(git rev-parse HEAD)
sed -i -e 's@"terriajs": ".*"@"terriajs": "'$GITHUB_REPOSITORY'#'${GITHUB_BRANCH}'"@g' package.json
Expand Down
2 changes: 1 addition & 1 deletion buildprocess/configureWebpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function configureWebpack(
useBuiltIns: "usage"
}
],
"@babel/preset-react",
["@babel/preset-react", { runtime: "automatic" }],
["@babel/typescript", { allowNamespaces: true }]
],
plugins: [
Expand Down
8 changes: 3 additions & 5 deletions lib/Charts/ChartView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ export default class ChartView {

@computed
get chartableItems(): ChartableMixin.Instance[] {
return <any>(
this.terria.workbench.items.filter(
(item) => ChartableMixin.isMixedInto(item) && item.chartItems.length > 0
)
);
return this.terria.workbench.items.filter(
(item) => ChartableMixin.isMixedInto(item) && item.chartItems.length > 0
) as any;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Core/instanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export default function instanceOf<T>(
type: Class<T>,
instance: any
): instance is T {
return instance instanceof <any>type;
return instance instanceof (type as any);
}
2 changes: 1 addition & 1 deletion lib/Core/markdownToHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function markdownToHtml(
// (typeof string === 'string'). So if this isn't a string primitive, call toString
// on it in order to make it one.
if (markdownString && typeof markdownString !== "string") {
stringToParse = (<any>markdownString).toString();
stringToParse = (markdownString as any).toString();
}
if (markdownOptions.injectTermsAsTooltips && markdownOptions.tooltipTerms) {
stringToParse = injectTerms(stringToParse, markdownOptions.tooltipTerms);
Expand Down
4 changes: 2 additions & 2 deletions lib/Map/Cesium/CesiumRenderLoopPauser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,14 @@ export default class CesiumRenderLoopPauser {

const cameraMovedInLastSecond = now - this._lastCameraMoveTime < 1000;

const surface = (<any>scene.globe)._surface;
const surface = (scene.globe as any)._surface;
const terrainTilesWaiting =
!surface._tileProvider.ready ||
surface._tileLoadQueueHigh.length > 0 ||
surface._tileLoadQueueMedium.length > 0 ||
surface._tileLoadQueueLow.length > 0 ||
surface._debug.tilesWaitingForChildren > 0;
const tweens = (<any>scene).tweens;
const tweens = (scene as any).tweens;

if (
!cameraMovedInLastSecond &&
Expand Down
20 changes: 10 additions & 10 deletions lib/Map/ImageryProvider/MapboxVectorTileImageryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,35 +185,35 @@ export default class MapboxVectorTileImageryProvider
get credit(): Credit {
let credit = this._credit;
if (credit === undefined) {
return <any>undefined;
return undefined as any;
} else if (typeof credit === "string") {
credit = new Credit(credit);
}
return credit;
}

get defaultAlpha(): number {
return <any>undefined;
return undefined as any;
}

get defaultBrightness(): number {
return <any>undefined;
return undefined as any;
}

get defaultContrast(): number {
return <any>undefined;
return undefined as any;
}

get defaultGamma(): number {
return <any>undefined;
return undefined as any;
}

get defaultHue(): number {
return <any>undefined;
return undefined as any;
}

get defaultSaturation(): number {
return <any>undefined;
return undefined as any;
}

get defaultMagnificationFilter(): any {
Expand All @@ -225,15 +225,15 @@ export default class MapboxVectorTileImageryProvider
}

get proxy(): DefaultProxy {
return <any>undefined;
return undefined as any;
}

get readyPromise(): Promise<boolean> {
return Promise.resolve(true);
}

get tileDiscardPolicy(): TileDiscardPolicy {
return <any>undefined;
return undefined as any;
}

getTileCredits(x: number, y: number, level: number): Credit[] {
Expand Down Expand Up @@ -326,7 +326,7 @@ export default class MapboxVectorTileImageryProvider

let pos;

let extentFactor = canvas.width / (<any>layer).extent; // Vector tile works with extent [0, 4095], but canvas is only [0,255]
let extentFactor = canvas.width / (layer as any).extent; // Vector tile works with extent [0, 4095], but canvas is only [0,255]

// Features
for (let i = 0; i < layer.length; i++) {
Expand Down
16 changes: 8 additions & 8 deletions lib/Map/ImageryProvider/ProtomapsImageryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,17 @@ export default class ProtomapsImageryProvider
readonly defaultNightAlpha = undefined;
readonly defaultDayAlpha = undefined;
readonly hasAlphaChannel = true;
readonly defaultAlpha = <any>undefined;
readonly defaultBrightness = <any>undefined;
readonly defaultContrast = <any>undefined;
readonly defaultGamma = <any>undefined;
readonly defaultHue = <any>undefined;
readonly defaultSaturation = <any>undefined;
readonly defaultAlpha = undefined as any;
readonly defaultBrightness = undefined as any;
readonly defaultContrast = undefined as any;
readonly defaultGamma = undefined as any;
readonly defaultHue = undefined as any;
readonly defaultSaturation = undefined as any;
readonly defaultMagnificationFilter = undefined as any;
readonly defaultMinificationFilter = undefined as any;
readonly proxy = <any>undefined;
readonly proxy = undefined as any;
readonly readyPromise = Promise.resolve(true);
readonly tileDiscardPolicy = <any>undefined;
readonly tileDiscardPolicy = undefined as any;

// Protomaps properties
/** Data object from constructor options (this is transformed into `source`) */
Expand Down
7 changes: 4 additions & 3 deletions lib/Map/Leaflet/ImageryProviderLeafletGridLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ export default class ImageryProviderLeafletGridLayer extends L.GridLayer {
}

createTile(tilePoint: L.Coords, done: L.DoneCallback) {
const canvas = <HTMLCanvasElement>(
L.DomUtil.create("canvas", "leaflet-tile")
);
const canvas = L.DomUtil.create(
"canvas",
"leaflet-tile"
) as HTMLCanvasElement;
const size = this.getTileSize();
canvas.width = size.x;
canvas.height = size.y;
Expand Down
49 changes: 28 additions & 21 deletions lib/Map/Leaflet/ImageryProviderLeafletTileLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
readonly imageryProvider: ImageryProvider,
options: L.TileLayerOptions = {}
) {
super(<any>undefined, {
super(undefined as any, {
...options,
updateInterval: defined((imageryProvider as any)._leafletUpdateInterval)
? (imageryProvider as any)._leafletUpdateInterval
Expand Down Expand Up @@ -153,7 +153,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {

createTile(coords: L.Coords, done: L.DoneCallback) {
// Create a tile (Image) as normal.
const tile = <HTMLImageElement>super.createTile(coords, done);
const tile = super.createTile(coords, done) as HTMLImageElement;

// By default, Leaflet handles tile load errors by setting the Image to the error URL and raising
// an error event. We want to first raise an error event that optionally returns a promise and
Expand All @@ -168,7 +168,12 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
.catch((e: unknown) => {
// The tile has failed irrecoverably, so invoke Leaflet's standard
// tile error handler.
(<any>L.TileLayer).prototype._tileOnError.call(this, done, tile, e);
(L.TileLayer as any).prototype._tileOnError.call(
this,
done,
tile,
e
);
});
return;
}
Expand All @@ -182,22 +187,22 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
};

L.DomEvent.on(tile, "error", (e) => {
const level = (<any>this)._getLevelFromZ(coords);
const level = (this as any)._getLevelFromZ(coords);
const message = i18next.t("map.cesium.failedToObtain", {
x: coords.x,
y: coords.y,
level: level
});
this._requestImageError = TileProviderError.handleError(
<any>this._requestImageError,
this._requestImageError as any,
this.imageryProvider,
<any>this.imageryProvider.errorEvent,
this.imageryProvider.errorEvent as any,
message,
coords.x,
coords.y,
level,
doRequest,
<any>e
e as any
);
});

Expand Down Expand Up @@ -228,10 +233,10 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
_update() {
if (!this.imageryProvider.ready) {
if (!this._delayedUpdate) {
this._delayedUpdate = <any>setTimeout(() => {
this._delayedUpdate = setTimeout(() => {
this._delayedUpdate = undefined;
this._update();
}, this._leafletUpdateInterval);
}, this._leafletUpdateInterval) as any;
}
return;
}
Expand All @@ -245,7 +250,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
this._delayedUpdate = undefined;
}

this._delayedUpdate = <any>setTimeout(() => {
this._delayedUpdate = setTimeout(() => {
this._delayedUpdate = undefined;

// If we're no longer attached to a map, do nothing.
Expand Down Expand Up @@ -287,19 +292,19 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
}

if (isDefined(this.imageryProvider.credit)) {
(<any>this._map).attributionControl.addAttribution(
(this._map as any).attributionControl.addAttribution(
getCreditHtml(this.imageryProvider.credit)
);
}

this._usable = true;

this._update();
}, this._leafletUpdateInterval);
}, this._leafletUpdateInterval) as any;
}

if (this._usable) {
(<any>L.TileLayer).prototype._update.apply(this, arguments);
(L.TileLayer as any).prototype._update.apply(this, arguments);

this._updateAttribution();
}
Expand Down Expand Up @@ -363,9 +368,11 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {

for (let j = ne.y; j < sw.y; ++j) {
for (let i = sw.x; i < ne.x; ++i) {
const credits = <Credit[]>(
this.imageryProvider.getTileCredits(i, j, zoom)
);
const credits = this.imageryProvider.getTileCredits(
i,
j,
zoom
) as Credit[];
if (!defined(credits)) {
continue;
}
Expand All @@ -380,7 +387,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
nextCredits.push(credit);

if (!credit._shownInLeafletLastUpdate) {
(<any>this._map).attributionControl.addAttribution(
(this._map as any).attributionControl.addAttribution(
getCreditHtml(credit)
);
}
Expand All @@ -391,7 +398,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
// Remove attributions that applied last update but not this one.
for (let i = 0; i < this._previousCredits.length; ++i) {
if (!this._previousCredits[i]._shownInLeaflet) {
(<any>this._map).attributionControl.removeAttribution(
(this._map as any).attributionControl.removeAttribution(
getCreditHtml(this._previousCredits[i])
);
this._previousCredits[i]._shownInLeafletLastUpdate = false;
Expand Down Expand Up @@ -446,7 +453,7 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
TerriaError.from(
e,
`An error ocurred while calling \`ImageryProvider#.pickFeatures\`. \`ImageryProvider.url = ${
(<any>this.imageryProvider).url
(this.imageryProvider as any).url
}\``
).log();
}
Expand All @@ -461,13 +468,13 @@ export default class ImageryProviderLeafletTileLayer extends L.TileLayer {
for (let i = 0; i < this._previousCredits.length; ++i) {
this._previousCredits[i]._shownInLeafletLastUpdate = false;
this._previousCredits[i]._shownInLeaflet = false;
(<any>map).attributionControl.removeAttribution(
(map as any).attributionControl.removeAttribution(
getCreditHtml(this._previousCredits[i])
);
}

if (this._usable && defined(this.imageryProvider.credit)) {
(<any>map).attributionControl.removeAttribution(
(map as any).attributionControl.removeAttribution(
getCreditHtml(this.imageryProvider.credit)
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Map/Leaflet/LeafletDataSourceDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class LeafletDataSourceDisplay {
const dataSources = this._dataSourceCollection;
const length = dataSources.length;
for (let i = 0; i < length; i++) {
const dataSource = <LeafletDataSource>dataSources.get(i);
const dataSource = dataSources.get(i) as LeafletDataSource;
if (isDefined(dataSource.update)) {
result = dataSource.update(time) && result;
}
Expand Down
Loading
Loading