Remove `hot` query string attribut when HL is disabled
Summary: public By doing this we fix 2 problems: 1. We use the same url, both the first time the simulator starts with Hot Loading disabled (no `hot` attribute), and after HL has been enabled and then disabled ('hot=false'). By doing so, the packager will rebuild more than one bundle as file changes. We could have ignored this attribute on the packager but I'd rather not contaminate the server with it and instead make the clients send only 2 types of URLs. 2. The code on `RCTBatchedBridge.m` that decides whether or not to enable HMR does so by looking at presence of the query string parameter `hot`. If the parameter is present, even when it's false, it will try to enable HL, which is wrong. Reviewed By: nicklockwood Differential Revision: D2807512 fb-gh-sync-id: 728b680c2383c328d8967d34c10e7a6288e455ac
This commit is contained in:
parent
d6513ca03f
commit
0f9c88514c
|
@ -79,6 +79,13 @@
|
|||
XCTAssertEqualObjects(result.absoluteString, @"http://example.com?bar=foo&foo=bar");
|
||||
}
|
||||
|
||||
- (void)testRemoveParam
|
||||
{
|
||||
NSURL *URL = [NSURL URLWithString:@"http://example.com?bar=foo&foo=bar"];
|
||||
NSURL *result = RCTURLByReplacingQueryParam(URL, @"bar", nil);
|
||||
XCTAssertEqualObjects(result.absoluteString, @"http://example.com?foo=bar");
|
||||
}
|
||||
|
||||
- (void)testNilURLAppendQueryParam
|
||||
{
|
||||
NSURL *URL = nil;
|
||||
|
|
|
@ -638,14 +638,20 @@ NSURL *RCTURLByReplacingQueryParam(NSURL *URL, NSString *param, NSString *value)
|
|||
}
|
||||
}];
|
||||
|
||||
NSString *encodedValue =
|
||||
[value stringByAddingPercentEncodingWithAllowedCharacters:URLParamCharacterSet];
|
||||
|
||||
NSString *newItem = [encodedParam stringByAppendingFormat:@"=%@", encodedValue];
|
||||
if (paramIndex == NSNotFound) {
|
||||
[queryItems addObject:newItem];
|
||||
if (!value) {
|
||||
if (paramIndex != NSNotFound) {
|
||||
[queryItems removeObjectAtIndex:paramIndex];
|
||||
}
|
||||
} else {
|
||||
[queryItems replaceObjectAtIndex:paramIndex withObject:newItem];
|
||||
NSString *encodedValue =
|
||||
[value stringByAddingPercentEncodingWithAllowedCharacters:URLParamCharacterSet];
|
||||
|
||||
NSString *newItem = [encodedParam stringByAppendingFormat:@"=%@", encodedValue];
|
||||
if (paramIndex == NSNotFound) {
|
||||
[queryItems addObject:newItem];
|
||||
} else {
|
||||
[queryItems replaceObjectAtIndex:paramIndex withObject:newItem];
|
||||
}
|
||||
}
|
||||
components.percentEncodedQuery = [queryItems componentsJoinedByString:@"&"];
|
||||
return components.URL;
|
||||
|
|
|
@ -544,7 +544,7 @@ RCT_EXPORT_METHOD(reload)
|
|||
BOOL actuallyEnabled = [self hotLoadingAvailable] && _hotLoadingEnabled;
|
||||
if (RCTGetURLQueryParam(_bridge.bundleURL, @"hot").boolValue != actuallyEnabled) {
|
||||
_bridge.bundleURL = RCTURLByReplacingQueryParam(_bridge.bundleURL, @"hot",
|
||||
actuallyEnabled ? @"true" : @"false");
|
||||
actuallyEnabled ? @"true" : nil);
|
||||
[_bridge reload];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue